regex

Regex for splitting a string using space when not surrounded by single or double quotes

Hello all. I'm new to regular expressions and would appreciate your help. I'm trying to put together an expression that will split the example string using all spaces that are not surrounded by single or double quotes. My last attempt looks like this: (?!") and isn't quite working. It's splitting on the space before the quote. Exampl...

Search Javascript Array for Regex and return True/False (0/1) if found

I need to know how I can search an array for some literal text and have it used as a condition whether to continue. Heres why: Each time I execute a function I am pushing the ID of the property it acts upon into an array. I need my funtion to check if that ID is in the array already and if it is, remove it and execute my other function ...

Regex: Is Lazy Worse?

I have always written regexes like this <A HREF="([^"]*)" TARGET="_blank">([^<]*)</A> but I just learned about this lazy thing and that I can write it like this <A HREF="(.*?)" TARGET="_blank">(.*?)</A> is there any disadvantage to using this second approach? The regex is definitely more compact (even SO parses it better). Edit: T...

Java regexp for file filtering

I would like to build a regexp in Java that would be passed in a FilenameFilter to filter the files in a dir. The problem is that I can't get the hang of the regexp "mind model" :) This is the regexp that I came up with to select the files that I would like to exclude ((ABC|XYZ))+\w*Test.xml What I would like to do is to select all ...

Extract comma separated portion of string with a RegEx in C#

Sample data: !!Part|123456,ABCDEF,ABC132!! The comma delimited list can be any number of any combination of alphas and numbers I want a regex to match the entries in the comma separated list: What I have is: !!PART\|(\w+)(?:,{1}(\w+))*!! Which seems to do the job, the thing is I want to retrieve them in order into an ArrayList or si...

Ruby Regex match unless escaped with \

Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey Where ~ or = denotes the beginning of match unless it is escaped with \ So it should match ~foo\~\=bar then =cheese then ~monkey I thought the following would work, but it doesn't. ([~=]([^~=]|\\=|\\~)+)(.*) What is a better regex ex...

javascript regex to extract anchor text and URL from anchor tags

Hello, I have a paragraph of text in a javascript variable called 'input_content' and that text contains multiple anchor tags/links. I would like to match all of the anchor tags and extract anchor text and URL, and put it into an array like (or similar to) this: Array ( [0] => Array ( [0] => <a href="http://yahoo...

Validating e-mail with regular expression VB.Net

I'm working on a small project in VB.Net where I get a input from a textbox, and need to verify that this is an e-email address. I found this expression "^[_a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", but i cant find any way to test if it passes. I want some code like: if not txtEmail.text = regexString then ...

PL/SQL function to return string with regexp special chars escaped

Is there an existing PL/SQL method which takes a string and returns the same string but with backslashes preceding any regexp chars? ...

RegEx matching with no single letter delimiter

Medicare Eligibility EDI Example Responses is what I'm trying to match. I have a string that looks like this: LN:SMITHbbbbbbbbFN:SAMANTHAbbBD:19400515PD:1BN:123456PN:9876543210GP:ABCDEFGHIJKLMNOID:123456789012345bbbbbPC:123PH:8005551212CD:123456PB:123ED:20060101TD:2070101LC:NFI:12345678FE:20070101FT:20080101 I need a set of matches th...

UTF in Python Regex

I'm aware that Python 3 fixes a lot of UTF issues, I am not however able to use Python 3, I am using 2.5.1 I'm trying to regex a document but the document has UTF hyphens in it – rather than -. Python can't match these and if I put them in the regex it throws a wobbly. How can I force Python to use a UTF string or in some way match a c...

Regex to find an integer within a string

I'm new to using regex and I'd like to use it with Java. What I want to do is find the first integer in a string. Example: String = "the 14 dogs ate 12 bones" Would return 14. String = "djakld;asjl14ajdka;sdj" Would also return 14. This is what I have so far. Pattern intsOnly = Pattern.compile("\\d*"); Matcher makeMatch = intsOnly....

How can I split a string into chunks of two characters each in Perl?

How do I take a string in Perl and split it up into an array with entries two characters long each? I attempted this: @array = split(/../, $string); but did not get the expected results. Ultimately I want to turn something like this F53CBBA476 in to an array containing F5 3C BB A4 76 ...

Python regex for MD5 hash

I've come up with: re.findall("([a-fA-F\d]*)", data) but it's not very fool proof, is there a better way to grab all MD5-hash codes? ...

Regex detect linebreak inside a XML node

I'm having troubles with a regexp. I'm looking through a set of XML files, and trying to detect some text inside specific nodes that contain a line break. Here is some sample data: <item name='GenMsgText'><text>The signature will be discarded.</text></item> <item name='GenMsgText'><text>The signature will be discarded.<break/> Do you ...

Validating file types by regular expression

I have a .NET webform that has a file upload control that is tied to a regular expression validator. This validator needs to validate that only certain filetypes should be allowed for upload (jpg,gif,doc,pdf) The current regular expression that does this is: ^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.doc|.DOC|.pd...

Error in Regex for String

I have simple regex "\".*\"" for me its says select everything between " and ", but it also catches "text") != -1 || file.indexOf(".exe" for me its two strings, for regex its one. how can i make regex to see that its two strings? P.S. I'm using Java. ...

What's wrong with this php/regex

The goal is to take the current working directory split it at /clients/ and see if the user is in [something]/clients/[their username]/[something] for example, the goal would be for input: cwd = "/volumes/raid0/www/clients/mikey/test_folder/" $session->username = "mikey" to return with $authorized = true I would like this to rec...

How can I match a quote-delimited string with a regex?

If I'm trying to match a quote-delimited string with a regex, which of the following is "better" (where "better" means both more efficient and less likely to do something unexpected): /"[^"]+"/ # match quote, then everything that's not a quote, then a quote or /".+?"/ # match quote, then *anything* (non-greedy), then a quote Assu...

Java equivalent to PHP's preg_replace_callback

I'm in the process of moving an application from PHP to Java and there is heavy use of regular expressions in the code. I've run across something in PHP that doesn't seem to have a java equivalent: preg_replace_callback() For every match in the regex, it calls a function that is passed the match text as a parameter. As an example us...