regex to retrieve specific url from text [duplicate] - javascript

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"/

Related

Regex find url with specefic character inside (js) [duplicate]

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 1 year ago.
I have the following text:
Some text
{\"url\": \"https:\/\/www.someurl.com\/200x200\/fsdffsde3e", \"bbb\"} kljkl
{\"url\": \"https:\/\/www.someurl.com\/500x500\/fsdffsde3e", \"bbb\"} kljkl
Some text
I want to extract all the URLs contains 200x200. so for example I need this URL: https:\/\/www.someurl.com\/200x200\/fsdffsde3e
this, will bring the entire row: "https(.*?)200x200(.*)" but I want only the URL.
Have a look: https://regex101.com/r/DDWLDM/1
Thanks
use This exp
"https(.*?)200x200(.*?)"

Find a specific value of a string between two chars/strings without knowing its value [duplicate]

This question already has answers here:
Get Substring between two characters using javascript
(24 answers)
Closed 2 years ago.
String example: "{something}" or "{word: something}"
What I need to do is get 'something', so the text between two specific parts of the string, in these case {-} and {word:-} (The 'something' part can change in every string, I never know what it is).
I tried using string.find() or regex but I didn't come up with a conclusion. What's the quickest and best way to do this?
What you need is a capture group inside a regex.
> const match = /\{([^}]+)\}/.exec('{foo}')
> match[1]
'foo'
The stuff in the parens, ([^}]+), matches any character but }, repeated at least once. The parens make it be captured; the first captured group is indexed as match[1].

How to remove set of string using regex [duplicate]

This question already has answers here:
How can I delete a query string parameter in JavaScript?
(27 answers)
Closed 5 years ago.
On the following string I want to remove sort=*. I can get this done by run loop over it But want to get it done using regex which is new to me.
So start point should be "sort" and end point should be '&' and sort value could be *
I have created this one but dont how to add end point
string.replace((sort=*)\w,'')
"category_id=249&sort=name&category_filter=15&"
to
"category_id=249&category_filter=15&"
You ca use this regex instead (sort=.*?&), which can match every thing from sort= until the first occurrence of &
regex demo
Output
category_id=249&category_filter=15&

Get text between tags regex javascript [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 4 years ago.
I am trying to get the text between the two tags which also handles multiple lines.I have managed to do it in PHP regex but i am stuck on the javascript one.
<any_tag>random text
dffdffdfdfdfdfdfdfd
dfdfdfdfdfdfdfdfdf
</any_tag>
I want to get the text between <any_tag> and </any_tag>
This is the regex for php
https://regex101.com/r/tQ1bX7/2
Now i am trying to achieve to same in javascript
Give try on following :
/[^(<any_tag>)](?:.*(\r?\n?).*)*(?=\<\/any_tag\>)/gi
Explination :
[^(<any_tag>)] match a single character not present in the list below
(<any_tag>) a single character in the list (<any_tg>) literally (case insensitive)

replace asterisk innerhtml javascript [duplicate]

This question already has answers here:
How do I replace an asterisk in Javascript using replace()?
(6 answers)
Closed 8 years ago.
how do i replace the asterisks with a blank ("") in the innerhtml using javascript?
i have tried this.
document.getElementById("lab").innerHTML = document.getElementById("lab").innerHTML.replace(/*/g, '');
and i also tried doing the asterisk itself but it gets commented..
searched everywhere i can't seem to find ways to remove the appended in innerhtml aside from replacing it with a blank.. are there any other options?
i also tried searching for ways to use replace and other options. for added info i am using this for the validation of a form
thanks in advance!
You have to escape the asterisk:
.....replace(/\*/g, "")
because it is a special character in regular expressions.

Categories