regex

Help with Regular Expression

Hello I need help with Regular Expression, I want to match each section (number and it's text - 2 groups), the text can be multi line, each section ends when another section starts (another number) or when .END is reached or EOF. Demo Expression: \(\d{1,3}\) ([\s\S]*?)(\.END|\(\d{1,3}\)) Input text: (1) some text some text ...

Regexp match in Java

Regexp in Java I want to make a regexp who do this verify if a word is like [0-9A-Za-z][._-'][0-9A-Za-z] example for valid words A21a_c32 daA.da2 das'2 dsada ASDA 12SA89 non valid words dsa#da2 34$ Thanks ...

What is the difference between using $1 vs \1 in Perl regex substitutions?

I'm debugging some code and wondered if there is any practical difference between $1 and \1 in Perl regex substitutions For example: my $package_name = "Some::Package::ButNotThis"; $package_name =~ s{^(\w+::\w+)}{$1}; print $package_name; # Some::Package This following line seems functionally equivalent: $package_name =~ s{^(\w...

Find Lines with N occurrences of a char

I have a txt file that I’m trying to import as flat file into SQL2008 that looks like this: “123456”,”some text” “543210”,”some more text” “111223”,”other text” etc… The file has more than 300.000 rows and the text is large (usually 200-500 chars), so scanning the file by hand is very time consuming and prone to error. Other similar (...

Change Number Format

I have a lot lines contains XXXXXXXXX-XXX.XXX number format. I want change number XXXXXXXXX-XXX.XXX to XX.XXX.XXX.X-XXX.XXX XXXXXXXXX-XXX.XXX = 15 digit random number Anyone can help me? Thanks in advance ...

Regex match pattern inside a wrapping pattern

I want match all phone numbers that are wrapped between << and >> tags. This regex for phone numbers: 0[2349]{1}\-[1-9]{1}[0-9]{6} I tired to add lookahead (and lookbehind) like (?=(?:>>)) but this didn't work for me. DEMO ...

ereg to preg conversion

I'm a complete novice when it comes to regex. Could someone help me convert the following expression to preg? ereg('[a-zA-Z0-9]+[[:punct:]]+', $password) An explanation to accompany any solution would be especially useful!!!! ...

Regex capturing named groups in a language that doesn't support them using a meta regex?

I am using Haskell and I don't seem to find a REGEX package that supports Named Groups so I have to implement it somehow myself. basically a user of my api would use some regex with named groups to get back captured groups in a map so /(?P<name>[a-z]*)/hhhh/(?P<surname>[a-z]*)/jjj on /foo/hhhh/bar/jjj would give [("name","foo"),("s...

Regex to strip tags, retain CDATA

Possible Duplicate: RegEx match open tags except XHTML self-contained tags Hi all, I know how everyone loves a regex question, so here is mine. I have an XML tree within which some nodes contain CDATA. How do I return just a string containing the data? Lets see an example <xml> <node>I'm plain text.</node> <node><![CDAT...

Does REGEX differ from PHP to Python

hi there, I found this post: http://stackoverflow.com/questions/118143/python-regex-vs-php-regex but I actually did not get if Python's REGEX syntax matches PHP's REGEX syntax. I started to convert some of my old PHP code to python (due to g's appengine etc.), and now I would like to know whether the regex is 100% convertable, by simpl...

The best way to deploy one site for two companies in ColdFusion?

My client has multiple companies; different names/logos etc, but all the content on the sites are identical with the exception of said names/logos. In a ColdFusion environment, what would be the best way for me to serve up identical content and swap out the logos/company names on the fly so I can keep everything in one spot? Is this a j...

Regex to match 0 - 999 but not blank

I'm working on a regex to match valid integer numbers such as the following: 0 1 99 999 However it should not allow matching an empty string. The closest I can get is: (0)|\\d{1,3} Which to me says a matching string will have either a zero or a series of digits between 1 and 3 characters long. However, empty strings still appear...

find all text before using regex

How can I use regex to find all text before the text "All text before this line will be included"? I have includes some sample text below for example This can include deleting, updating, or adding records to your database, which would then be reflex. All text before this line will be included You can make this a bit more sophisticate...

Using regex to separate a multipart email

Before you guys go telling me that Regex is the epitome of all evil... I already know. If I had more hair it would be ripped out already. So onto the question. I have made a parser using regex that strips out the desired parts of an html email. Why on earth would I want to do that? Because I'm still a beginner programmer ok, if you can ...

Match all characters in group except for first and last occurrence

Say I request parent/child/child/page-name in my browser. I want to extract the parent, children as well as page name. Here are the regular expressions I am currently using. There should be no limit as to how many children there are in the url request. For the time being, the page name will always be at the end and never be omitted. ...

Regex group capturing problem

If I had an html string containing this somewhere in the middle of it: <img src="http://images.domain.com/Images/hello.jpg" alt="Failed to Load" /> What regex would I use in order to just obtain the name of the image file? i.e. hello.jpg Currently I am using this: (?<front>.*<img.*src="http://images.domain.com/Images/)(?&lt;imgN...

Split string data into array based on new line and then double digit number

What I'm looking to do is split data from string into an array. Here's the general idea of the text format... xxxxx denotes any mix of alpha-numeric-whitespace data. xxxxx 1 xxxxxxxxxx 2 xxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxx 3 xxxxxxxxxx 4 xxxxxxxxxx xxxxxxxxxx 5 xxxxxxxxxx (When numbers get into the double digits, the ten's ...

javascript regex : only letters allowed

Hi, Quick questio : I need to allow an input to only accept letters, from a-z to A-Z, but can't find any expression for that, using javascript test() method. Cheers! ...

Help with shell script - Rename filenames (remove special chars) in a directory?

I have a directory of csv files with spaces and all kinds of characters. How do I rename them? The following gives an error. #! /bin/bash cd DirectoryName for file in *.csv; do #echo $file filename=${file%.*} file_clean=${filename//[ ()$+&\.\-\'\,]/_} final= "$file_clean.csv" mv "$file" $final done cd .. Thanks!...

Complex edit xml file

For example, we have this xml: <x> <y>some text</y> <y>[ID] hello</y> <y>world [/ID]</y> <y>some text</y> <y>some text</y> </x> and we need to remove words "[ID]", "[/ID]" and text between them (which we don't know, when parsing), of course without damage xml formatting. The only solution i can think is that: ...