regex

MySQL strip non-numeric characters to compare

I'm looking to find records in a table that match a specific number that the user enters. So, the user may enter 12345, but this could be 123zz4-5 in the database. I imagine something like this would work, if PHP functions worked in MySQL. SELECT * FROM foo WHERE preg_replace("/[^0-9]/","",bar) = '12345' What's the equivalent functi...

Need a good regex to convert URLs to links but leave existing links alone

I have a load of user-submitted content. It is HTML, and may contain URLs. Some of them will be <a>'s already (if the user is good) but sometimes users are lazy and just type www.something.com or at best http://www.something.com. I can't find a decent regex to capture URLs but ignore ones that are immediately to the right of either a do...

Using regular expressions to do mass replace in Notepad++ and Vim

So I've got a big text file which looks like the following: <option value value='1' >A <option value value='2' >B <option value value='3' >C <option value value='4' >D It's several hundred lines long and I really don't want to do it manually. The expression that I'm trying to use is: <option value='.{1,}' > Which is working as inte...

Regular Expression to validate hex string

Hi, I'm using this simple regular expression to validate a hex string ^[A-Fa-f0-9]{16}$ as you can see I'm using a quantifier to validate that the string is 16 chars long, I was wondering if I can use another quantifier in the same regex to validate the string length to be either 16 or 18 (not 17). Thanks in advance :) ...

How do I remove carriage returns with Ruby?

I thought this code would work, but the regular expression doesn't ever match the \r\n. I have viewed the data I am reading in a hex editor and verified there really is a hex D and hex A pattern in the file. I have also tried the regular expressions /\xD\xA/m and /\x0D\x0A/m but they also didn't match. This is my code right now: li...

Is there a way to use RegEx in ASP/VBScript?

I have an ASP website which I need to add a RegEx match to. Is there any support for RegEx in ASP/VBScript? Thank you, Brett ...

Match everything inbetween two tags with Regular Expressions?

How can I match (PCRE) everything inbetween two tags? I tried something like this: <!--\s*LoginStart\s*-->(.*)<!--\s*LoginEnd\s*--> But it didn't work out too well for me.. I'm kind of new to regular expressions, so I was hoping if someone would be kind enough to explain to me how I would accomplish this, if its even possible wit...

JavaScript RegEx for div tags

I have a JavaScript variable which holds an HTML page and due to the setup I need to extract everything between <div id="LiveArea"> and </div> from that variable using JavaScript. Any help is greatly appreciated. ...

$1 and \1 in Ruby

When using regular expressions in Ruby, what is the difference between $1 and \1? ...

Why does this regular expression kill the Java regex engine?

I have this naive regex "<([\s]|[^<])+?>" (excluding the quotation marks). It seems so straightforward but it is indeed evil when it works against the below HTML text. It sends the Java regular expression engine to an infinite loop. I have another regex ("<.+?>"), which does somewhat the same thing, but it doesn't kill anything. Do you...

Can I use named groups in a Perl regex to get the results in a hash?

Is it possible to perform a named-group match in Perl's regex syntax as with Python's? I always bind the $n values to proper names after matching, so I'd find it more convenient to do it in the regex itself if it's possible. Python does it like so: >>> import re >>> regex = re.compile(r'(?P<count>\d+)') >>> match = regex.match('42') >>...

Cannot get regular expression work correctly with multiline

I have a quite big XML output from an application. I need to process it with my program and then feed it back to the original program. There are pieces in this XML which needs to be filled out our replaced. The interesting part looks like this: <sys:customtag sys:sid="1" sys:type="Processtart" /> <sys:tag>value</sys:tag> here ar...

Javascript regex to match a person's height

Hi, I need a javascript regex pattern to match a person's height to check if the input is valid. Here are some sample input: 5' 9" 6' 5'8" Any ideas? ...

How do I disallow numbers in a regular expression?

Hello I was writing a Regular Expression (first time in my life I might add) but I just can't figure out how to do what I want. So far, so good since I already allow only Letters and spaces (as long as it's not the first character) now what I'm missing is that I don't want to allow any numbers in between the characters...could anybody he...

Regex pattern for numeric values

I need an regular expression pattern to only accept positive whole numbers. It can also accept a single zero. I do not want to accept decimals, negative number and numbers with leading zeros. Any suggestions? ...

What characters must I escape in a Perl pre-compiled regex?

I'm having a hard time determining what characters must be escaped when using Perl's qr{} construct I'm attempting to create a multi-line precompiled regex for text that contains a myriad of normally escaped characters (#*.>:[]) and also contains another precompiled regex. Additionally I need to match as strictly as possible for testing...

regex for alphanumeric word, must be 6 characters long.

Hi, What is the regex for a alpha numeric word, at least 6 characters long (but at most 50). ...

Split a Pascal-case string into logical set of words

I would like to take a pascal-cased string like "CountOfWidgets" and convert it into something more user-friendly like "Count of Widgets" in C#. Multiple adjacent uppercase characters should be left intact. What is the most efficient way to do this? NOTE: Duplicate of http://stackoverflow.com/questions/155303/net-how-can-you-split-a-cap...

how search for a substring found within a string of text and highlight all of it

I'm trying to highlight the search results but I want to include the surrounding text that is limited by the enclosing tags. So if the $term is "cool" the preg_replace should end up with: <div><span style="background: #f00">My hair cut so cool!</span></div> Unfortunately my regex doesn't seem to capture the surrounding text, only the...

excluding characters in \S regex match

I have the following regex expression to match html links: <a\s*href=['|"](http:\/\/(.*?)\S['|"]> it kind of works. Except not really. Because it grabs everything after the < a href... and just keeps going. I want to exclude the quote characters from that last \S match. Is there any way of doing that? EDIT: This would make it grab on...