I’m trying to match all the images elements as strings, This is my regex: This works, but I want to extract the src of all the images. So when I execute the regular expression on this String: <img src=”http://static2.ccn.com/ccs/2013/02/img_example.jpg /> it returns: “http://static2.ccn.com/ccs/2013/02/img_example.jpg” Answer You need to use a capture group () to extract the urls, and if you’re wanting
Tag: regex
JS Regex to find href of several a tags
I need a regex to find the contents of the hrefs from these a tags : Just the urls, not the href/ tags. I’m parsing a plain text ajax request here, so I need a regex. Answer You can try this regex: Example at: http://regexr.com?333d1 Update: or easier via non greedy method:
Regex for allowing alphanumeric,-,_ and space
I am searching for a regular expression for allowing alphanumeric characters, -, _ or spaces in JavaScript/jQuery. How can this be done? Answer Try this regex:
Find everything that’s not an email address using only regex
I need to find everything in a string that is not an e-mail address. Here is my version of how to find an e-mail address. I want to modify this regex to find the inverse–everything other than the e-mail address in any string. ###Example 1: asdasd ###Example 2: 123@asd.com sda Note: I want to get status == true in the
Replace each leading and trailing whitespace with underscore using regex in javascript
The output should look like this This code works fine for the trailing whitespaces but all the leading whitespaces are replaced with just one underscore. The working php regex for this is: /Gs|s(?=s*$)/ Answer Not pretty, but gets the job done
How can i get the red green and blue values from an rgb/rgba string?
If I have the string rgba(111,222,333,0.5) how can i extract the individual colours from the string, i.e. I would like to be able to use a neat clean solution for this so I am assuming a regular expression would be best? Answer I’d avoid regex for a predictable string, and suggest: JS Fiddle demo. Or, given that you want an
How to replace non-printable unicode characters (Javascript)
I’ve already wasted a good amount of time dealing with strings (generated by some other source) and I found out that the problem was that the strings have non-printable characters. Today I am dealing with javascript. Does anyone know how to replace non-printable unicode characters in javascript? I found something similar here: How can I replace non-printable Unicode characters in
check if number string contains decimal?
After doing a sqrt() How can I be check to see if the result contains only whole numbers or not? I was thinking Regex to check for a decimal – if it contains a decimal, that means it didn’t root evenly into whole numbers. Which would be enough info for me. but this code isnt working… I bet there’s other
Regexp Matching Hex Color Syntax (and Shorten form)
Well, I’m pretty new on regex and in particular on JavaScript regexp. I’m looking for making a regexp that match the hex color syntax (like #34ffa6) Then I looked at the w3school page: Javascript RegExp Object Then that’s my regexp: It seems to work but, if I want it to match also the “short hex color syntax” form? (like #3fa),
JavaScript, regex: How to fetch mail address in mailto: links
Is there a jquery plugin or may be a regex which can be used to all the fields in query string of a mailto: link. It should support the mailto syntax. Say if I have a link like … The regex should give me the mail addresses in mailto: link – astark1@unl.edu, id@internet.node. It should also support links like For