[Solved] How to use regular expression replacement string [closed]

var str=”@username(123) test@username2(234) test” document.write(str.replace(/@(\w+?)\((\d+?)\)/g, ‘<a href=”https://stackoverflow.com/questions/16208629/localhost/home/userid=”>$1</a>’)); // Result: <a href=”https://stackoverflow.com/questions/16208629/localhost/home/userid=123″>username</a> test<a href=”localhost/home/userid=234″>username2</a> test solved How to use regular expression replacement string [closed]

[Solved] How do I parse “N/A – -0.09%” and extract the number after the first hyphen in PHP? [closed]

I wouldn’t use a regex here, I’d just remove the two quotes (replacing ” with nothing using str_replace()), then split the string into words (using explode() with ‘ ‘ as the delimiter), then grab the last “word” using array_pop(). url=”abc123.php”; $data = file_get_contents($url); //$data contains “N/A – -0.09%” (the string to parse) $match = array_pop(explode(‘ … Read more

[Solved] replace the matched expression from string and its next charecter?POST operation

You may want to try out the following regex. Regex101 link ((?:\?.*?&|\?)journey=)[^&]* Try out the following code to replace the value of journey to replacement string url = “http://www.whitelabelhosting.co.uk/flight-search.php?dept=any&journey=R&DepTime=0900″; string newUrl = Regex.Replace(url, @”((?:\?.*?&|\?)journey=)[^&]*”, “$1″+”replacement”); Remember to add the following to your file: using System.Text.RegularExpressions; You can do the same for DepTime using the following … Read more

[Solved] How could a viable transformation look like that does convert a product-name into a valid HTML id-attribute value? [closed]

You can try this- const data = [ “2-inch leg extension”, “2′ x 8′ Overhead Garage Storage Rack”, “4 Drawer Base Cabinet 16-1/2\”W x 35\”H x 22-1/2\”D”, “24\” Long Tool Bar w/ Hooks Accessory” ]; const res = data.map(str => str.replace(/[^a-z\d\-_]/ig, ”)); console.log(res); If you need any prefix with the ID then add it like- … Read more

[Solved] REGEX – Get specific values [closed]

If this is an exercise in using Regular Expressions, so you really want to use a Regular Expression to solve it, you can do something like this: regex = /^(PL|PH|MH|M)$/ choices = [“PL”, “PH”, “M”, “MH”, “other”, “invalid”, “value”] index = Math.floor(Math.random() * choices.length) input = choices[index] console.log(“Testing”, ‘”‘+input+'”‘) x = input.match(regex) if (x) { … Read more

[Solved] ruby how to match a substring [closed]

To get an input out of the whole file: ▶ input = input[/PLAY RECAP.*?^(.+?)^localhost/m, 1] To hashify the result: ▶ input.scan(/(\S+) : ok=(\w+)/).to_h #⇒ { # “ec2-123.compute-1.amazonaws.com” => “16”, # “ec2-456.compute-1.amazonaws.com” => “11”, # “ec2-766.compute-1.amazonaws.com” => “40” # } To sort by host name (thx Wiktor Stribiżew for the reminder.) input.scan(/(\S+) : ok=(\w+)/) .to_h .sort_by … Read more

[Solved] Custom regular expression [closed]

How about: \d{1,2}(?:[.,]\d{1,2})? explanation: \d{1,2} : one or two digits (?: : start non capture group [.,] : . or , \d{1,2} : one or two digits )? : end group, optional 1 solved Custom regular expression [closed]

[Solved] PHP – Replace part of a string [closed]

Use a regular expression. str_replace will only replace static values. $RAMBOX = ‘hardwareSet[articles][123]’; $Find = ‘/hardwareSet\[articles\]\[\d+\]/’; $Replace=”hardwareSetRAM”; $RAMBOX = preg_replace($Find, $Replace, $RAMBOX); Output: hardwareSetRAM The /s are delimiters. The \s are escaping the []s. The \d is a number. The + says one or more numbers. Regex101 Demo: https://regex101.com/r/jS6nO9/1 If you want to capture the … Read more

[Solved] Javascript remove leading zeros and decimal points from string [closed]

You could try the below string.replace function. Use ^ to tell the regex engine to do the matching operation from the start. By putting 0 and . inside a character class would match either 0 or dot. string.replace(/^[0.]+/, “”) Example: > “0.015.000”.replace(/^[0.]+/, “”) ‘15.000’ > “0.150.000”.replace(/^[0.]+/, “”) ‘150.000’ > “015.000”.replace(/^[0.]+/, “”) ‘15.000’ 0 solved Javascript … Read more

[Solved] Merging several strings in PHP [closed]

Give that a go, Works for me <?php $test = array(); $test[]=”serverA”; $test[]=”serverA.something.com”; $test[]=”serverA”; $test[]=”serverB”; $test[]=”serverB.something.com”; $test[]=”serverC”; $test[]=”serverD.something.com”; sort($test); $final = array(); $temp = “#”; for($i=0,$count = count($test);$i<$count;$i++){ if(substr( $test[$i], 0, strlen($temp) ) == $temp) $temp = $test[$i]; else { $final[] = $temp; $temp = $test[$i]; } } //unset first unset($final[0]); //add in last $final[] … Read more

[Solved] Regular expression doesn’t produce expected result

You can make use of re.split to split into sections and then look for the [failed] string in the each section: splitted = re.split(r'(\d{1,2})\.(.*)(?= _{3,})’, text) failed = [(splitted[i-2], splitted[i-1]) for i, s in enumerate(splitted) if re.search(r’\[failed\]’, s)] failed # [(‘9’, ‘TX_MULTI_VERIFICATION 2412 DSSS-1 NON_HT BW-20 TX1′), # (’11’, ‘TX_MULTI_VERIFICATION 2472 DSSS-1 NON_HT BW-20 TX1’), … Read more

[Solved] Regular expression to match something followed by two different string [closed]

If the name doesn’t contain whitespaces then you have to look for the first whitespace instead of the word “inflicted”. I would try something like ^(.*?)\s.*?$ You can simply test regular expressions online for example with https://regex101.com/ EDIT Depending on your comment also whitespaces are possible in the name. So we cannot search for the … Read more