I have this search controller and I want to set it up to check every letter in search input but I don't know how to do it with regex.  module.exports.search = (req, res, next) =&gt; {   Character.find({     $or: [       { firstName: req.query.search },       { lastName: req.query.search }     ]   })     .then(characters =&gt; {       res.status(200).send(characters);     })     .catch(next); }   Also, I have tried with   { firstName: /req.query.search/ }   , but it doesn't work. Any help would be great.
6461
I would like to create a String.replaceAll() method in JavaScript and I'm thinking that using a regex would be most terse way to do it.  However, I can't figure out how to pass a variable in to a regex.  I can do this already which will replace all the instances of "B" with "A".  "ABABAB".replace(/B/g, "A");   But I want to do something like this:  String.prototype.replaceAll = function(replaceThis, withThis) {     this.replace(/replaceThis/g, withThis); };   But obviously this will only replace the text "replaceThis"...so how do I pass this variable in to my regex string?
18468
I'm developing an algorithm to parse a number out of a series of short-ish strings. These strings are somewhat regular, but there's a few different general forms and several exceptions. I'm trying to build a set of regexes that will handle the various forms and exceptions; I'll apply them one after another to see if I get a match.   One of these forms goes something like this:  X (Y) Z   Where:   X is a number I want to capture.  Z is static, pre-defined text. it's basically how I determine whether this particular form is applicable or not. Y is a a string of unknown length and content, surrounded by parenthesis.    Also: Y is optional; it doesn't always appear in a string with Z and X. So, I want to be able to extract the numbers from all of these strings:   10 Z 20 (foo) Z 30 (bar) Z   Right now, I have a regex that will capture the first one:  ([0-9]+) +Z   My problem is that I don't know how to construct a regex that will match a series of characters if and only if they're enclosed in parenthesis. Can this be done in a single regex?
12451
In the Stack Overflow podcast #36 (), this opinion was expressed: Once you understand how easy it is to set up a state machine, you’ll never try to use a regular expression inappropriately ever again. I've done a bunch of searching.  I've found some academic papers and other complicated examples, but I'd like to find a simple example that would help me understand this process.  I use a lot of regular expressions, and I'd like to make sure I never use one &quot;inappropriately&quot; ever again.
77035
I've been playing around with emacs lisp, and I wanted to write a little function to do a regular expression search and replace.  I had a heck of a time getting the regular expression to work correctly because I didn't realize that all the special characters need to be double escaped when writing lisp code (but not when using query-replace-regexp interactively!).    So for example, using query-replace-regexp interactively you can use   ^\(.*\)[\t]-.*$   but when writing elisp code you need to double escape everything like so:   ^\\(.*\\)[\t]-.*$     I finally found a reference to this in a Steve Yegge , but I was wondering if anyone knew why this is?
1603
We used to be able to , but that now appears to be broken.  I'd expect a  to return a result, but instead the search engine appears to put quotes around the whole request; the search box shows the search has been replaced with "[python] += list" and the  I was looking for doesn't appear among the returned questions.  Using quotes around the symbols do not seem to help here;  returns an empty result.
4355
For example, this regex  (.*)&lt;FooBar&gt;   will match:  abcde&lt;FooBar&gt;   But how do I get it to match across multiple lines?  abcde fghij&lt;FooBar&gt;
25338
I need to search a string and replace all occurrences of %FirstName% and %PolicyAmount% with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from using the String.Replace() method. I've seen web pages on the subject that suggest  Regex.Replace(strInput, strToken, strReplaceWith, RegexOptions.IgnoreCase);   However for some reason when I try and replace %PolicyAmount% with $0, the replacement never takes place. I assume that it has something to do with the dollar sign being a reserved character in regex.   Is there another method I can use that doesn't involve sanitizing the input to deal with regex special characters?
3211
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000020: Document 1 - Completed successfully  I'm trying to extract pieces from it using regex. In this case, I want to grab everything after Project Name up to the part where it says J0000011: (the 11 is going to be a different number every time). Here's the regex I've been playing with: Project name:\s+(.*)\s+J[0-9]{7}:  The problem is that it doesn't stop until it hits the J0000020: at the end. How do I make the regex stop at the first occurrence of J[0-9]{7}?
119008
Given this string:  SET @text = "&lt;a href=""https://salesforce.stackexchange.com""target=""_blank""&gt;Salesforce&lt;/a&gt; &lt;a href=""https://stackoverflow.com"" target=""_blank""&gt;Everything else&lt;/a&gt;"   And this function:  SET @matching = '\s+(?:[^&gt;]*?\s+)?href="([^"]*)"' SET @output = RegExMatch(@text, @matching, 1)   How can I manage to find and print an arbitrary number of matches in my string? E.g. in above example, I would like to present e.g. a rowset with each URL in each row.
101419
I've got a string in .NET which is actually a URL.  I want an easy way to get the value from a particular parameter. Normally, I'd just use Request.Params[&quot;theThingIWant&quot;], but this string isn't from the request.  I can create a new Uri item like so: Uri myUri = new Uri(TheStringUrlIWantMyValueFrom);  I can use myUri.Query to get the query string...but then I apparently have to find some regexy way of splitting it up. Am I missing something obvious, or is there no built in way to do this short of creating a regex of some kind, etc?
73427
How can i check if a list has certain string in salesforce. For example I have : anotherList which is from controller and has  this value [NAME_A, NAME_B, NAME_C]  Then in my page:      &lt;apex:repeat var="list" value="{!tesList}"&gt;         &lt;input type="checkbox" style="display:{!IF(CONTAINS(anotherList, list['name']), '','none')}" value="{!list['name']}" /&gt;     &lt;/apex:repeat&gt;   But i got an error saying that Error: Incorrect parameter type for function 'CONTAINS()'. Expected Text, received Object  So parameters should only be Strings right? But how can i do something like this in Visualforce page?  &lt;!-- JSTL sample --&gt;     &lt;c:forEach var="list" items="${testList}"&gt;             &lt;c:if test="${fn:contains(anotherList, list.name)}"&gt;                 &lt;input type="checkbox"  value="${list.name}" /&gt;             &lt;/c:if&gt;     &lt;/c:forEach&gt;
118631
A friend asked me this and I was stumped: Is there a way to craft a regular expression that matches a sequence of the same character? E.g.,  match on 'aaa', 'bbb', but not 'abc'?  m|\w{2,3}|    Wouldn't do the trick as it would match 'abc'.  m|a{2,3}|    Wouldn't do the trick as it wouldn't match 'bbb', 'ccc', etc.
41896
I need to compare 2 strings as equal such as these:     Lubeck == Lübeck   In JavaScript.  Why? Well, I have an auto-completion field that's going out to a Java service using Lucene, where place names are stored naturally (as Lübeck), but also indexed as normalized text,   import sun.text.Normalizer; oDoc.setNameLC = Normalizer.normalize(oLocName, Normalizer.DECOMP, 0)     .toLowerCase().replaceAll("[^\\p{ASCII}]","");   This way some-one who doesn't know to type "Mèxico" can type "mexico" and get a match which returns "Mèxico" (among a lot of other possible hits, like "Café Mèxico, Dubai, UAE").  Now the thing is I don't have the ability to change the service to do any highlighting on the server side, therefore I am highlighting on the client JavaScript side with something like:  return result.replace( input.replace(/[aeiou]/g,"."), "&lt;b&gt;$1&lt;/b&gt;");   It's a little more fancy because I am escaping special regex characters in the input. This is fine for simple one word matches at the beginning of a hit, but it really breaks down if you suddenly wish to support multi-word matches like "london cafe":  input = input.strip().toLowerCase(); //fyi prototype's strip is like trim re = new RegEx(input.replace(/[aeiou]/g,".").replace(/\s+/g,"|"),"gi"); return result.replace(re, "&lt;b&gt;$1&lt;/b&gt;");   This doesn't work for say "london ca" (was typing london cafe), because it would mark "Jack London Cabin, Dawson City, Canada" as: "Ja&lt;b&gt;ck&lt;/b&gt; &lt;b&gt;London&lt;/b&gt; &lt;b&gt;ca&lt;/b&gt;bin, Dawson &lt;b&gt;Ci&lt;/b&gt;ty, &lt;b&gt;Ca&lt;b/&gt;nada" [note the "ck" and "Ci" particularly]  Therefore I'm sort of looking for something that's not as crazy as:  input = input.strip().toLowerCase(); input = input.replace(/a/g,"[ÀàÁáÂâÃãÄäÅåÆæĀāĂăĄą]"); input = input.replace(/e/g,"[ÈèÉéÊêËëĒēĔĕĖėĘęĚě]"); // ditto for i, o, u, y, c, n, maybe also d, g, h, j, k, l, r, s, t, w, z  re = new RegEx(input.replace(/\s+/g,"|"),"gi"); return result.replace(re, "&lt;b&gt;$1&lt;/b&gt;");   Is there a compiled table I can refer to mapping a range of characters which are accented versions of an other character to that character, by which I don't mean the plain unicode chart. And if so, could I avoid using weird, possibly slow, RegEx statements?  About the bounty: Before I started a bounty there were two answers, the one pointing me to doing it in Ruby, and  that  wrote which was a completion of the basic form I'd put in my question. Now don't get me wrong, I really appreciate working it out as completely as he did, but I just wished that there might be another way.  It seems so far that everyone who's dropped by to look at the question and answer has decided that MizzardX covers it just fine, or that they have no different approach. I would be interested in a different approach, and if it simply isn't available before the bounty closes, MizzardX will win the bounty (though in a cruel twist, his edits mad it a community wiki answer, so I'm not sure if he'll get the bounty!)
20352
Is it possible to detect a valid regular expression with another regular expression?  If so please give example code below.
32515
I'm after a regex that will validate a full complex UK postcode only within an input string. All of the uncommon postcode forms must be covered as well as the usual. For instance:  Matches   CW3 9SS SE5 0EG SE50EG se5 0eg WC2H 7LT   No Match   aWC2H 7LT WC2H 7LTa WC2H   How do I solve this problem?
58099
I would like to have a regular expression that checks if a string contains only upper and lowercase letters, numbers, and underscores.
2660
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.