Non greedy grep
I want to grep the shortest match and the pattern should be something like: <car ... model=BMW ...> ... ... ... </car> ... means any character and the input is multiple lines. ...
I want to grep the shortest match and the pattern should be something like: <car ... model=BMW ...> ... ... ... </car> ... means any character and the input is multiple lines. ...
Hi there, I'm using a regex to match Bible verse references in a text. The current regex is REF_REGEX = re.compile(''' (?<!\w) # Not preceded by any words (?P<quote>q(?:uote)?\s+)? # Match optional 'q' or 'quote' followed by many spaces (?P<book> (?:(?:[1-3]|I{1,3})\s*)?...
Hi I am trying to use the following regular expression to check whether a string is a positive number with either zero decimal places, or 2: ^\d+(\.(\d{2}))?$ When I try to match this using preg_match, I get the error: Warning: preg_match(): No ending delimiter '^' found in /Library/WebServer/Documents/lib/forms.php on line 862 ...
What I want to do is replace the "[replace]" in input string with the corresponding vaule in the replace array. The total number of values will change but there will always be the same number in the replace array as in input string. I have tried doing this with preg_replace and preg_replace_callback but I can't get the pattern right for ...
Is that possible to pass variable into regular expression pattern string in jquery ( or javascript)? For example, I want to validate a zip code input field every time while user type in a character by passing variable i to the regular expression pattern. How to do it right? $('#zip').keyup( function(){ var i=$('#zip').val().length ...
I want to change <lang class='brush:xhtml'>test</lang> to <pre class='brush:xhtml'>test</pre> my code like that. <?php $content="<lang class='brush:xhtml'>test</lang>"; $pattern=array(); $replace=array(); $pattern[0]="/<lang class=([A-Za-z='\":])* </"; $replace[0]="<pre $1>"; $pattern[1]="/<lang&...
I have to filter user input to on my web ASP.NET page: <asp:TextBox runat="server" ID="recipientBankIDTextBox" MaxLength="11" /> <asp:RegularExpressionValidator runat="server" ValidationExpression="?" ControlToValidate="recipientBankIDTextBox" ErrorMessage="*" /> As far is I know SWIFT code must contain 5 or 6 letters and other symbol...
I want to convert <p>Code is following</p> <pre> <html><br></html> </pre> to <p>Code is following</p> <pre> <html> </html> </pre> I don't know how to write regular expression for replace between pre tag in PHP. I tried this code http://stackoverflow.com/questions/1517102/replace-newlines-with-br-tags-but-on...
Can some please help me with regular expression for height in cm ( eg. 170.25)(after dot only 2 character), weight in kg ( eg. 57.750) (after dot only 3 character),both numeric. this kind of value format should be accepted Height: 57,57.55 or 150,150.55 Weight: 77,77.55,77.565 or 150,150.77,150.777 ...
Consider the following snippet: puts 'hello'.gsub(/.+/, '\0 \\0 \\\0 \\\\0') This prints (as seen on ideone.com): hello hello \0 \0 This was very surprising, because I'd expect to see something like this instead: hello \0 \hello \\0 My argument is that \ is an escape character, so you write \\ to get a literal backslash, thus \\...
I'm having trouble checking in PHP if a value is is any of the following combinations letters (upper or lowercase) numbers (0-9) underscore (_) dash (-) point (.) no spaces! or other characters a few examples: OK: "screen123.css" OK: "screen-new-file.css" OK: "screen_new.js" NOT OK: "screen new file.css" I guess I need a regex fo...
Hi, I'm trying to do some parsing that will be easier using regular expressions. The input is an array (or enumeration) of bytes. I don't want to convert the bytes to chars for the following reasons: Computation efficiency Memory consumption efficiency Some non-printable bytes might be complex to convert to chars. Not all the bytes ...
Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I'd specifically like to know if it's possible under the .NET Platform. ...
(If you can make a better title, please do) Hi, I need to make sure a string matches the following regex: ^[0-9a-zA-Z]{1}[0-9a-zA-Z\.\-_]*$ (Starts with a letter or number, then any number of letters, numbers, dots, dashes or underscores) But given that, I need to make sure it doesn't match a Guid, my Guid matching reg-ex looks like...
In scala.util.matching.Regex trait MatchData I see that there support for groupnames , I thought that this was related to (Regex Named Capturing Groups) But since Java does not support groupnames until version 7 as I understand it (ref), Scala version 2.8.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6. gives me this exception: scala>...
I need to extract a specific Id from a html document but the problem is that the id must not "be used". Here is the html content http://pastebin.com/wF2dx8JZ As you may see there are different html blocks . Some of them contain the "Used" word so I need to extract only the first id which is not used. Basically I can write a simple p...
Suppose I was trying to match the following expression using regex.h in C++, and trying to obtain the subexpressions contained: /^((1|2)|3) (1|2)$/ Suppose it were matched against the string "3 1", the subexpressions would be: "3 1" "3" "1" If, instead it were matched against the string "2 1", the subexpressions would be: "2 1" "2...
I'm implementing a c# program that should automatize a Mono-alphabetic substitution cipher. The functionality i'm working on at the moment is the simplest one: The user will provide a plain text and a cipher alphabet, for example: Plain text(input): THIS IS A TEST Cipher alphabet: A -> Y, H -> Z, I -> K, S -> L, E -> J, T -> Q Cipher ...
Is there a way to grab and export the match part only in a pattern search without changing the current file? For example, from a file containing: 57","0","37","","http://www.thisamericanlife.org/Radio_Episode.aspx?episode=175" 58","0","37","","http://www.thisamericanlife.org/Radio_Episode.aspx?episode=170" I want to export a new fil...
In the article, Vim Regular Expressions, Oleg Raisky gives the following command to reduce multiple blank lines to a single blank: :g/^$/,/./-j Can someone please describe how this works? I know :g command and regular expressions. But I didn't understand what the part /,/./-j does. ...