This question already has answers here:
How to get URL parameter using jQuery or plain JavaScript?
(34 answers)
Closed 7 years ago.
I am trying to get an id from a url string generated in php depending on the page you are viewing the id can appear in different places for example
site.com/view.php?id=12&person=23
or
site.com/view.php?loc=man&id=1782&person=43
I just need to get the id section using JQuery any ideas
You can use regex to get the id from URL.
var id = url.match(/id=(\d+)/)[1]
DEMO
REGEX Explanation
/: Delimiters of regex
id=: Matches literal id=
() : Capturing group
\d+: Matches one or more numbers
Related
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(.*?)"
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&
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)
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:
Best HashTag Regex
(9 answers)
Closed 7 years ago.
How to replace twitter style #hashtags with JavaScript?
I.e.
this is a #hashtag should become this is a #hashtag.
For PHP: Parse text for hashtags and replace with links using php
t = 'this is a #hashtag'
t.replace(/#(\w+)/g, '#$1')
Gives
this is a #hashtag