regex

Regex (.NET) for strings ending with FIRST OCCURENCE of "xyz"

I need a regex that matches first "xyz" and all characters that come before. For example, for "abxyzcdxyz" it should match "abxyz". I was trying with pattern ".*xyz", but it matches the entire string. ...

Cleaning up a SQL SP with Regex

1) If I am running a find and replace in SQL 2005 - what would be the regular expression to find tab and space sequences ( or space and tab sequences ) and replace them with just tab? 2) If I have a line which begins with a space - is there a regular expression to convert that leading space to a tab? 3) What would be the regular expres...

A regex that will parse 00.00

I'm trying to create a regex that will accept the following values: (blank) 0 00 00.0 00.00 I came up with ([0-9]){0,2}\.([0-9]){0,2} which to me says "the digits 0 through 9 occurring 0 to 2 times, followed by a '.' character (which should be optional), followed by the digits 0 through 9 occuring 0 to 2 times. If only 2 digits are ...

How to strip all parameters and the domain name from a URL using javascript?

Given a series of URLs http://www.anydotcom.com/myfolder/some-url.html http://www.anydotcom.com/myfolder2/index.html# http://www.anydotcom.com/myfolder3/index.html?someParam=aValue http://www.anydotcom.com/foldername/index.html?someParam=anotherValue First, how could I strip anything off the end of the URL so that I end up with http://...

Matching parenthesis content in PCRE without outermost parens

I need to extract content of unbalanced paren construction. In manual for PCRE i found solution for matching balanced parens. <\[ ( (?>[^(<\[|\]>)]+) | (?R) )* \]> For my test <[<[ab<[cd]>]><[ef]> It extracts 0.0: <[ab<[cd]>]> 0.1: <[ef]> But i want to extract same content without outermost parens: 0.0: ab<[cd]> 0.1: ef Could...

Regex to search for a word in a string in Visual Studio

I need to search all of my codebase for "Url" and replace it with "URL". If I search for Url in Visual Studio I also get all my variables with "Url" in it. Anyone have a Regex I can use to only find Url within a quoted string e.g. "Use this Url:"? Edit I was looking looking for a quick and dirty way to find designer text and hard cod...

How to negate specific word in regex?

I know that I can negate group of chars as in [^bar] but I need a regular expression where negation applies to the specific word - so in my example how do I negate an actual "bar" and not "any chars in bar" ...

Regular Expression to match a word

How do I create a regular expression to match a word at the beginning of a string. We are looking to match stop at the beginning of a string and anything can follow it. For example the expression should match: stop stop random stopping Thanks. ...

RegEx to match 123.45 and E123.4 and V12.34

I'm trying to create a RegEx that matches the 3 patterns listed above. I can somewhat create a working RegEx for any of those 3 but my problem is creating one that works with all 4 of those. The allowed values are below, where D is any digit and the '.' is never present as a trailing character (i.e. DDD. wouldn't be valid). Also the V...

Regex: Match a string containing numbers and letters but not a string of just numbers.

Question I would like to be able to use a single regex (if possible) to require that a string fits [A-Za-z0-9_] but doesn't allow: Strings containing just numbers or/and symbols. Strings starting or ending with symbols Multiple symbols next to eachother Valid test_0123 t0e1s2t3 0123_test te0_s1t23 t_t Invalid t__t ____ 0123012...

iPhone: RegexKit vs. RegexKit lite - going through an array takes very very long

For my app I need to see if an url is Matched by a regex string. so I created an array with all the regex strings (about 1000+ strings) and check them using RegexKit lite: for (NSString * aString in mainDelegate.whiteListArray) { if (![urlString isMatchedByRegex:aString]) { it works but sadly this operation takes very very long. at l...

Explanation of Lookaheads in This Regular Expression

I understand regular expressions reasonably well, but I don't get to make use of them often enough to be an expert. I ran across a regular expression that I am using to validate password strength, but it contains some regex concepts I am unfamiliar with. The regex is: ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}$ and in plain English it mea...

Do all regular expressions halt?

Is there any regular expression that will, for some input string, search for a match forever? ...

C# Regular expresson to get parenthesized info

Hi all, I need a regular expression that will match text enclosed in parentheses. The parentheses should be included. Here are some examples. String: "(AB123-16W) DJ2988W61" Should match: "(AB123-16W)" String: "(6541238 Rev. B, PS B1 & PS B2) 62MJ301-29 Rev. NC" Should match: "(6541238 Rev. B, PS B1 & PS B2)" Any ideas? ...

Regular expression for file path which doesn't allow parent directories

I'm looking to write a regex for a file path that must start with some prefix. In this case it should start with '/tank/home/'. I also want to make sure that it contains no '/..' -- no jumping up to parent directories. I spent a while fiddling around without coming up with anything quite right. I settled on using two regexes, the first ...

Make links clickable with regex

Is there a regex out there that can find a string that contains a word that starts with either http:// or www and wrap it with <a>$1</a>? Been googling but I can't seem to find a ultimate one. Another question, Could you somehow make it ignore it if its inside a <img> tag ? Thanks a bunch! ...

text parsing in ruby

Hi..I am a naive programmer in ruby..just learing to write hello worlds using ruby. i need one help in parsing text in ruby given @BreakingNews: Typhoon Morakot hits Taiwan, China evacuates thousands http://news.bnonews.com/u4z3 something like this i would like to eliminate all the hyperlinks. and get plain text. :@BreakingNews: Typhoon...

Stylistic Help - jQuery regex parsing

I've written some jQuery for parsing an id out of a link's href. It works, but I'm wondering if there's a cleaner, more idiomatic jQuery way of doing it: <a class="edit_tags" href="/image/edit_tags/id/2">Edit Tags</a> <script type="text/javascript" charset="utf-8"> $('.edit_tags').click(function(event) { event.preventDefault(); ...

Problem using regex to extract text

Hello! I need to extract from the following lines of code <label for="<%=foobar.bar %>">Password:</label> <label for="foobar">Password:</label> I need to extract foobar, I can use this: (?<=for=")[^"]+(?=(")) to extract: <%=foobar.bar %> and foobar but I don't want <%= or .bar and if I try to create (?<=for=")[^"]+(?=(")) | (?...

REGEX: Separe intervals between commas

may be duplicate I am using PHP and postgres. How can I separate words in the form below? The maximun amount of words is 7. word_1, word_2, word_3, ... ...