regex

regular expression

Hi, I need to find all invocations of some logging macros in the code. The macro invocation is of the form: DEBUG[1-5] ( "methodName: the logged message", arguments) But the new versions of the macros are prepending the name of the method automatically, so my task is to write a Python script that will remove the duplicate function na...

Elegant way to distinct Path or Entry key

I have an application loading CAD data (Custom format), either from the local filesystem specifing an absolute path to a drawing or from a database. Database access is realized through a library function taking the drawings identifier as a parameter. the identifiers have a format like ABC 01234T56-T, while my paths a typical windows P...

PHP, what is the better choice for removing a known string?

I am looking to search for and replace a known string from within another string. Should I use str_replace() or preg_replace()? The string to be replaced would be something similar to [+qStr+], [+bqID+], or [+aID+] and it would be being searched for in a code chunk similar to this: <li> [+qStr+] <ol class="mcAlpha"> <li><input...

How can I create an acronym from a string in MATLAB?

Is there an easy way to create an acronym from a string in MATLAB? For example: 'Superior Temporal Gyrus' => 'STG' ...

PHP RegEx - Get All Digits

I have this code: $string = "123456ABcd9999"; $answer = ereg("([0-9]*)", $string, $digits); echo $digits[0]; This outputs '123456'. I'd like it to output '1234569999' ie. all the digits. How can I achieve this. I've been trying lots of different regex things but can't figure it out. ...

RegEx - Indexed/Arrayed Named Capture Groups?

I have a situation where something can appear in a format as follows: ---id-H-- Header: data Another Header: more data Message: sdasdasdasd Message: asdasdasdasd Message: asdasdasd There may be many messages, or just a couple. I'd prefer not having to step outside of RegEx, because I am using the RegEx to parse some header information...

JSLint reports "Insecure ^" for my regex -- what does that mean?

I'm trying to get my Javascript code 100% JSLint clean. I've got a regular expression: linkRgx = /https?:\/\/[^\s;|\\*'"!,()<>]+/g; JSLint reports: Insecure '^' What makes the use of the negation of the character set "insecure" ? ...

Python: Elegant way to check if at least one regex in list matches a string

Hi. I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this code: list = ['s...

Regular Expression for CSV with numbers

I'm looking for some regular expression to help parse my CSV file. The file has lines of number,number number,number Comment I want to skip number,number number,number Ex: 319,5446 564425,87 Text to skip 27,765564 I read each line into a string and I wanted to use some regular express to make sure the line matches the pattern of ...

Regex AND operator

Based on this answer http://stackoverflow.com/questions/469913/regular-expressions-is-there-an-and-operator I tried the following on http://regexpal.com/ but was unable to get it to work. What am missing? Does javascript not support it? Regex: (?=foo)(?=baz) String: foo,bar,baz ...

How to do a proper search/replace using GREP Regular Expressions in a text editor?

I am trying to run some regular expressions(grep) on a text file of about 4K lines. The main portion that I need replaced looks like this: 1,"An Internet-Ready Resume",1,2,""," And I need it to look like this: <item> <title>An Internet-Ready Resume</title> <category>1</category> <author>2</author> <content> So far, this is what I ...

regex , php, preg_match

I'm trying to extract the mileage value from different ebay pages but I'm stuck as there seem to be too many patterns because the pages are a bit different . Therefore I would like to know if you can help me with a better pattern . Some examples of items are the following : http://cgi.ebay.com/ebaymotors/1971-Chevy-C10-Shortbed-Truck-/25...

Regular expression help

Possible Duplicate: help with regex needed I need a regular expression for which: the string is alphanumeric and have exactly 6 characters in the first half followed by hyphen(optional) followed by optional 4 characters:(cannot have more than 4 characters in the second half) so any of the following is valid 11111A 111111-1 ...

regular expression repeating subexpression

I have the following text <pattern name="pattern1"/> <success>success case 1</success> <failed> failure 1</failed> <failed> failure 2</failed> <unknown> unknown </unknown> <pattern name="pattern4"/> <pattern name="pattern5"/> <success>success case 3</success> <pattern name="pattern2"/> <success>success case 2</success> ...

jQuery: match currency with a regular expression

In the following: <span>This cost $15.99 per item</span> how do I return "$15.99" using jquery? The value can also be for example "$7". ...

How to split a space separated file?

Hi I am trying to import this: http://en.wikipedia.org/wiki/List_of_countries_by_continent_%28data_file%29 which is of the format like: AS AF AFG 004 Afghanistan, Islamic Republic of EU AX ALA 248 Åland Islands EU AL ALB 008 Albania, Republic of AF DZ DZA 012 Algeria, People's Democratic Republic of OC AS ASM 016 American Samoa EU AD ...

Use Regular expression with fileinput

Hello, I am trying to replace a variable stored in another file using regular expression. The code I have tried is: r = re.compile(r"self\.uid\s*=\s*('\w{12})'") for line in fileinput.input(['file.py'], inplace=True): print line.replace(r.match(line), sys.argv[1]), The format of the variable in the file is: self.uid = '027FC8E...

PHP regular expression subpattern behaviour

I want to match both the src and title attributes of an image tag: pattern: <img [^>]*src=["|\']([^"|\']+["|\'])|title=["|\']([^"|\']+) target: <img src="http://someurl.jpg" class="quiz_caption" title="Caption goes here!"> This pattern gives me one unwanted match, title="content", and the match I actually want which is the value b...

What does this regex do?

^.+\\(.*\\) I am struggling to work this one out, any help would be greatly appreciated... also is there a site that lets youu paste in a regular expression then spits out in plain text what it means? ...

regex:search character still not perfect

i have this code: <script type="text/javascript"> var str="KD-R35H2UND"; var patt1=/[G|T|EE|EJU].*D/i; document.write(str.match(patt1)); </script> by using code at var patt1=... i can show like this: if i type KD-R35ED => SHOW ED KD-R35UND => UND KD-R35JD => JD KD-R35TJD => TJD KD-R35EED=> EED my problem is: if i type KD-R35GD it c...