This question already has answers here:
Extract all email addresses from bulk text using jquery
(8 answers)
Closed 4 years ago.
I am trying to extract multiple email addresses from a string of text using a regex in Zapier code.
var rawList = "This is just a test of everything#test.com not sure how regex#email.com can extract multiple email#addresses.com but we will see";
var emailList = rawList.match(/\b[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,}\b/);
console.log(emailList)
This always returns emailList as null. I pulled this regex expression from https://www.regular-expressions.info/index.html I have also tried Email regular expressions from other websites with still the same experiences.
I have also used Zapier's Formatter's Extract Pattern option and tried the same expression with no luck either. Not sure what is going on here?
Your regex code doesn't work. You should use /(([A-Za-z0-9]+\w*[\.\-]?){1,}\w*#([A-Za-z0-9]+\.){1,2}[A-z]{2,3})/gm.
See test below.
var rawList="This is just a test of everything#test.com not sure how regex#email.com can extract multiple email#addresses.com but we will see";
var emailList=rawList.match(/(([A-Za-z0-9]+\w*[\.\-]?){1,}\w*#([A-Za-z0-9]+\.){1,2}[A-z]{2,3})/gm);
console.log(emailList);
Related
This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 2 years ago.
I have a string like this:
let temp = 'Hi {{username}}, Your request with request id: {{requestId}} has been processed. Please contact your nearest shop.'
I want this array from the string:
['userName', 'requestId']
I know I have to somehow use regular expressions to achieve this but I can't figure out the pattern for achieving this.
NOTE: This is just an example string and I want a more general approach to solve this problem coz the string may vary.
You need to use positive lookahead. Here is the regex which works for your case.
let temp = 'Hi {{username}}, Your request with request id: {{requestId}} has been processed. Please contact your nearest shop.'
temp.match(/(?<={{)(\w+)(?=}})/g)
This question already has answers here:
Match exact string
(3 answers)
Closed 5 years ago.
I have a regular expression I've adapted from Michael Hartl's rails book that I'm using to validate email addresses
/\A([\w+\-]\.?)+#[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
I want to use this for validation in javascript, but it doesn't work there, and I can't seem to figure out why. I'm just spinning my wheels here
So the above one works in Rails, but doesn't work in JS. I've found other expressions I can use in JS that work, but I want to try to use the same ones to keep it consistent.
For clarification, this is the rails side:
email = "test#test.com"
return /\A([\w+\-]\.?)+#[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
this returns true
and on the JS side:
email = "test#test.com"
return /^\A([\w+\-]\.?)+#[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.test( email );
this returns false
Any pointers?
Per the comment by #Wiktor Stribiżew the missing piece was changing the regex syntax to work with JS, like this
return /^([\w+\-]\.?)+#[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+$/i.test( email );
I took out the \A and \z and replaced them with \^ and $, respectively
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 6 years ago.
I'm building a basic application which lets the user to share or continue their search status between sessions with # parameters in Javascript (I'm building this as a SPA so GET parameters won't always necessarily work).
In my app I could have a URI like: /items#rarity=rare,common,uncommon&cost=ascending&category=primary
If I wanted to check what state to set the cost filter in my react component, I'd want to extract asecnding and then check the ascending checkbox to set the state on page load.
If I use Javascript's split function combined with regex, I can capture all information on cost by doing:
var hash = window.location.hash;
hash = hash.split(/cost.*&/);
Right now, this will obviously return an array in two parts the first being /items#rarity=rare,common,uncommon& and category=primary as the split function will split on the condition supplied which in my case matches the string from regex.
Is there any way I can capture the extracted string from the split function so I can then parse the cost string?
No way. Oh, there is! Just wrap your regex in the capture group.
var s = '/items#rarity=rare,common,uncommon&cost=ascending&category=primary';
r = s.split(/(cost.*&)/);
console.log(r[0]);
console.log(r[1]); //there is the "thrown" part
console.log(r[2]);
To achieve expected result, use below
var x="/items#rarity=rare,common,uncommon&cost=ascending&category=primary";
console.log(x.split('cost=')[1].substring(0,x.split('cost=')[1].indexOf("&")));
http://codepen.io/nagasai/pen/RRyLmA
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:
Closed 12 years ago.
Possible Duplicates:
Checking for a valid url using Javascript Regular Expressions
PHP validation/regex for URL
I have a if statement that will check if the user entered a URL(HTTP Protocol only), like this:
if(/^regexp/.test(url))
But how should be this regular expression to check if the text is a URL or not?
I believe this little function might help:
function isURL(string){
regEx = /(\b(https?|ftp):\/\/[-A-Z0-9+&##\/%?=~_|!:,.;]*[-A-Z0-9+&##\/%=~_|])/gim;
return regEx.test(string));
}
Let us know if it worked out!
W.