I have a this regular expression below for some input name fields. How do I include an apostrophe and a hyphen in this? Answer Hyphen is already included (twice), you can add the apostrophe by just editing it into the character class: You can rewrite it to look like this, so that there’s no need to escape the hyphen and
Tag: regex
Javascript: highlight substring keeping original case but searching in case insensitive mode
I’m trying to write a “suggestion search box” and I cannot find a solution that allows to highlight a substring with javascript keeping the original case. For example if I search for “ca” I search server side in a case insensitive mode and I have the following results: Calculator calendar ESCAPE I would like to view the search string in
Remove empty tags using RegEx
I want to delete empty tags such as <label></label>, <font> </font> so that: will be cleaned as: I have this RegEx in javascript, but it deletes the the empty tags but it also delete this: “<i>italic</i></p>” What I am missing? Answer You have “not spaces” as your character class, which means “<i>italic</i></p>” will match. The first half of your regex
jQuery Youtube URL Validation with regex
I know there is plenty of question answered over here https://stackoverflow.com/questions/tagged/youtube+regex, but not able find a question similar to me. Any body has the JavaScript Regular expression for validating the YouTube VIDEO URL’s line below listed. Just want to know where such a URL can be possible — update 1– — update 2– This one worked almost fine, but failed
Regex for replacing a single-quote with two single-quotes
I’m running into an issue that I think is being caused by needing to double-up on some single quotes inside a string. However, JS’s string.replace uses RegEx, and I’ve never built a RegEx by hand. Can someone help me build a RegEx to find a single quote and replace it with two single quotes? Answer Try this:
How can I invert a regular expression in JavaScript?
I have a string A and want to test if another string B is not part of it. This is a very simple regex whose result can be inverted afterwards. I could do: and invert it afterwards, like this: The problem I have is, that I need to do it within the regular expression and not with their result. Something
How to extract base URL from a string in JavaScript?
I’m trying to find a relatively easy and reliable method to extract the base URL from a string variable using JavaScript (or jQuery). For example, given something like: http://www.sitename.com/article/2009/09/14/this-is-an-article/ I’d like to get: http://www.sitename.com/ Is a regular expression the best bet? If so, what statement could I use to assign the base URL extracted from a given string to a
Parse and add url from clipboard
I need a javascript bookmark to take the url I have in the clipboard parse out the 2 numbers and create a new url, and add a link to the top of the page, that when clicked adds the url to my bookmark menu. Say I have url’s like these http://www.website.com/frontpageeditor.jhtml?sectionID=2844&poolID=6276 javascript:getPoolPageUrl(9800,22713) Then I need to add the numbers to
RegEx for Javascript to allow only alphanumeric
I need to find a reg ex that only allows alphanumeric. So far, everyone I try only works if the string is alphanumeric, meaning contains both a letter and a number. I just want one what would allow either and not require both. Answer Update (supporting universal characters) if you need to this regexp supports universal character you can find
Is there a version of JavaScript’s String.indexOf() that allows for regular expressions?
In javascript, is there an equivalent of String.indexOf() that takes a regular expression instead of a string for the first first parameter while still allowing a second parameter ? I need to do something like and While String.search() takes a regexp as a parameter it does not allow me to specify a second argument! Edit: This turned out to be