This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Closed 3 years ago.
I have a simple regex I'm using and that works perfectly in chrome but edge throws a syntax error, ths is the line :
var html=text.match(/^<div.+\/div>$/ims);
I don't see the problem.
Because /s flag is not supported, use:
var html=text.match(/^<div[\s\S]+\/div>$/im);
Basically you want to match all characters with a new line character
You can this regex please:-
text.match(/^<div>.+\n*.*<\/div>/)
Related
This question already has answers here:
Regex works on browser but not in Node.js
(2 answers)
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 4 years ago.
I have the following regex that works when used on the chrome browser:
file.match(/(?<=__\()(.*)(?=\))/g);
But it seems to throw an error when using Node on my machine:
SyntaxError: Invalid regular expression: /(?<=__\()(.*)(?=\))/: Invalid group
Any ideas why this might be? Also I am trying to match string that appear in groups like this:
__("string to match");
const file = "__('string to be extracted');";
const strings = file.match(/(?<=__\()(.*)(?=\))/g);
console.log(strings);
This question already has an answer here:
Javascript RegEx Not Working [duplicate]
(1 answer)
Closed 5 years ago.
I tried the following JavaScript in developer console of Chrome:
s = "mysessionId=PsGymRfxWIQG9gjNGgRlKw"
s.match("mysessionId=([^\s\;]+)")
A little surprised by the result:
["mysessionId=P", "P"]
I had expected that the () in regexp will match the entire "PsGymRfxWIQG9gjNGgRlKw", instead, it only matched the first character "P".
When I tried the regexp in perl, it does match the entire sessionId.
Any idea why?
I should have used // instead of "".
s.match(/mysessionId=([^\s\;]+)/)
Had to laugh the moment when I figured it out.
This question already has answers here:
Regular Expression to find a string included between two characters while EXCLUDING the delimiters
(13 answers)
Closed 7 years ago.
An API I use returns this text:
<http://192.168.1.10:8080/longUrl>; rel="recording-session",
<http://192.168.1.10:8080/realLongUrl>; rel="h264-session-sdp",
<http://192.168.1.10:8080/realLongDifferentUrl>; rel="h264-session-sdp",
<rtp://239.1.1.18:5006>; rel="destination-high",
<rtp://239.1.1.17:5006>; rel="destination-low"
I'm trying to retrieve the first URL that is followed by ; rel="h264-session-sdp.
So in this case that would be: http://192.168.1.10:8080/realLongUrl
I've been fiddling around trying to modify examples found here on SO, but just can's seem to get it right.
try this one /([^<]+)(?:>; rel\=\"h264\-session\-sdp\")/
Selects the text inbetween the greater then and less then characters:
?<=\<)(.*?)(?=>)
https://regex101.com/r/oS5sX6/1
And if you wanted to select the urls on multiple lines, add the g and m modifiers:
/(?<=\<)(.*?)(?=>)/gm
https://regex101.com/r/oS5sX6/2
Try this:
/(?<=\<)(.*?)(?=\>)>; rel="h264-session-sdp"/
This question already has answers here:
How do I replace an asterisk in Javascript using replace()?
(6 answers)
Closed 7 years ago.
I am trying to replace the same string *a*a consistently with *a.
Tried many variations of something like this, but none really worked:
s = s.replace( /\b*a*a\b/g, "*a");
So far running this leads to all xzy*a being replaced with xyz
* is a special regex character. If you want to match only an actual asterisk, then you have to escape it like this:
s = s.replace( /\*a\*a/g, "*a");
Working demo: http://jsfiddle.net/jfriend00/gvgshwyz/
An asterisk is a special regex character.
You just have to escape it like this: \*a in place of *a
This question already has answers here:
Why do regex constructors need to be double escaped?
(5 answers)
Closed 7 years ago.
I'm using the following JavaScript code to create a regular expression to match a UK mobile number:
new RegExp("(\+44|0)7\d{9}", 'g');
However, I get an error in the console log saying:
Uncaught SyntaxError: Invalid regular expression: /(?:+44|0)7d{9}/:
Nothing to repeat
Similar questions on StackOverflow point to a missing escaped character, but mine seem to be fine.
I have also tried without the global flag.
Help would be greatly appreciated.
You can create RegExp by using short method
var a = /(\+44|0)7\d{9}/g
Its must works good)