Posts

Showing posts with the label regex

replace text to variable's value using jquery

replace text to variable's value using jquery I have created a function to get sms message from db using ajax get call and after success i want to replace the {order_id} text to order-id like 454574 and may b few more variables like customer name etc. sms message ajax get call {order_id} 454574 MY TRY $(document).delegate('.sms-template', 'click', function() { var tempID = $(this).attr('id').replace('sms-template-',''); var oID = $(this).attr('data-id').replace('sms-template-',''); $.ajax({ url: 'index.php?route=sale/order/getSmsTemplate&token=<?php echo $token; ?>&template_id='+tempID, type: 'get', dataType: 'json', success: function(json) { $('textarea#input-order-comment-'+oID).append(json['message']); }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "rn" + xhr.statusText ...

Select first dash only with regex in JavaScript

Select first dash only with regex in JavaScript How to select the first dash - only and before the space? - HEllo Good - That is my - first world HEllo Good - That is my - first world The regex I wrote .+?(?=-) selected HEllo Good - That is my . .+?(?=-) HEllo Good - That is my If I have only the string HEllo Good - That is my , it looks ok, but with the space. HEllo Good - That is my var string = 'HEllo Good - That is my - first world'; console.log(string.match(/.+?(?=-)/gm)); please add the wanted result as well. – Nina Scholz Jun 30 at 8:30 Your title and your question ask different things ("everything before first dash" vs. "first dash only"). – T.J. Crowder Jun 30 at 8:30 ...

How to get description with php regular expression?

How to get description with php regular expression? Iam making a webcrawler and I need to extract the metadata that contains the description, this is what I did: $html = file_get_contents('http://www.google.com'); preg_match('/<meta name="description" content="(.*)"/>i', $html, $description); $description_out = $description; var_dump($description_out); and I get this error Warning: preg_match(): Unknown modifier '>' in C:xampphtdocswebcrawlerphp-web-crawlerindex.php on line 21 What is the correct regular expression? Possible duplicate of RegEx match open tags except XHTML self-contained tags – Yunnosch Jun 30 at 5:56 2 Answers 2 Your pattern is incorrect. You start with a / delimiter and then you ha...

Regex to keep the last 4 characters of a string of unknown length

Image
Regex to keep the last 4 characters of a string of unknown length I need to use Regex to keep the last 4 characters of a string. I don't know the length of the string so I need to start at the end and count backwards. The program is written in c#. Below are two examples: 840057 1002945 I need to be left with: 0057 2945 I have tried ^....(.*) and ^.{0,4} but this leaves me with 3 or 4 characters depending on the length of the string. ^....(.*) ^.{0,4} When I try .{4}$ I am left with 100 and not the last 4 digits 2945. Below is a code snippet which may help. Thank you, I appreciate the help. and if the string isnt 4 chars long? – Gordon Jun 29 at 12:42 this would work /....$/ – Harpreet Singh Jun 29 at 12:43 ...

Extract Id from Twitch Clip URL

Extract Id from Twitch Clip URL How can I extract the Id of a Twitch Clip URL. Example: https://clips.twitch.tv/KindYummyCarrotPeteZaroll?some=1 I need only the Id part, for example: https://clips.twitch.tv/[ID]?v=1 https://clips.twitch.tv/[ID]?v=1 The Id in the top example is KindYummyCarrotPeteZaroll . Any query string if comes after should be ignored and not be part of the Id. KindYummyCarrotPeteZaroll I tried: MatchCollection matches = Regex.Matches(url, @"^(https://clips.twitch.tv/)(?:(?!http).)*?"); But I wasn't able to capture the Id in a group. I am using ASP.NET and C#. Try (?<=twitch.tv/)(w*)(?=?) – pkpkpk Jun 30 at 7:10 (?<=twitch.tv/)(w*)(?=?) 1 Answer 1 No need for Regex: string str = "https://clips.twitch.tv/KindYum...