regex

Remove leading whitespaces using variable length lookbehind in RegExp

Hello, I'm wondering if variable length lookbehind assertions are supported in JavaScript's RegExp engine? For example, I'm trying to match the string "variable length" in the string "[a lot of whitespaces and/or tabs]variable length lookbehind", and I have something like this but it does not go well in various RegExp testers: ^(?<=[ ...

regex: trim all strings directly preceeded by digit except if string belongs to predefined set of strings.

I've got addresses I need to clean up for matching purposes. Part of the process is trimming unwanted suffices from housenumbers, e.g: mainstreet 4a --> mainstreet 4. However I don't want: 618 5th Ave SW --> 618 5 Ave SW in other words there are some strings (for now: st, nd, rd, th) which I don't want to strip. What would b...

What is the Regular Expression For "Not Whitespace and Not a hyphen"

I tried this but it doesn't work : [^\s-] Any Ideas? ...

How can I check with a regex that a string contains only certain allowed characters?

I need a special regular expression and have no experience in them whatsoever, so I am turning to you guys on this one. I need to validate a classifieds title field so it doesn't have any special characters in it, almost. Only letters and numbers should be allowed, and also the three Swedish letters å, ä, ö (upper- or lowercase). Besi...

Javascript: regular expression

I need to replace a substring from some string. I've already created corrected code for doing it. But I amn't sure is it best way. Please, see code below: var str = 'test ruby,ruby on rails,ruby,' var substr = 'ruby'; var reg = new RegExp(',' + substr + ',|^' + substr + ',', 'gi'); str.replace(reg, ','); //returns "test ruby,ruby on rai...

Regex query: how can I search PDFs for a phrase where words in that phrase appear on more than one line?

I am trying to set up an index page for the weekly magazine I work on. It is to show readers the names of companies mentioned in that weeks' issue, plus the page numbers they are appear on. I want to search all the PDF files for the week, where one PDF = one magazine page (originally made in Adobe InDesign CS3 and Adobe InCopy CS3)....

ruby parametrized regular expression

I have a string like "{some|words|are|here}" or "{another|set|of|words}" So in general the string consists of an opening curly bracket,words delimited by a pipe and a closing curly bracket. What is the most efficient way to get the selected word of that string ? I would like do something like this: @my_string = "{this|is|a|test|case}...

Regular expression for Regular expressions?

I have an app that enables the user to input a regular expression, my question is how to check against any input of regular expressions and make sure they are valid ones because if they are not there will be preg_match errors. I don't want to use the '@' before preg_match, so if there's a way to check the validity of the user input of r...

Helping to make some easy regular exspression

Hi. I need reg exspression what make this "123.12312" -> "123.32", or "23.323" -> "23.32" in c#. It must be only 2 digits after point :) ...

Regular Exression "^[a-zA-Z]" or "[^a-zA-Z]"

Is there a difference between ^[a-zA-Z] and [^a-zA-Z]? When I check in C#, Regex.IsMatch("t", "^[a-zA-Z]") // Return true (I think it's correct) Regex.IsMatch("t", "[^a-zA-Z]") // Return false There are alot of web site using [^a-zA-Z] for alphabet. I'm not really sure which one is correct answer. Could someone please shed the ...

Javascript to match a specific number using regular expressions

I was using javascript to detect for specific key strokes and while writing the method I thought I'd try regular expressions and the test() method and came up with: if (/8|9|37|38|46|47|48|49|50|51|52|53|54|55|56|57|96|97|98|99|100|101|102|103|104|105|110/.test(num)) { // do something if there's a match } This doesn't seem to work...

java Regular expression matching html

solution: this works: String p="<pre>[\\\\w\\\\W]*</pre>"; I want to match and capture the enclosing content of the <pre></pre> tag tried the following, not working, what's wrong? String p="<pre>.*</pre>"; Matcher m=Pattern.compile(p,Pattern.MULTILINE|Pattern.CASE_INSENSITIVE).matcher(input); if(m.find()){ ...

How to change img src string from ending with _m to _t using jquery for a set of images

Hello guys, I was hoping to get a nice push in the right direction I would like to change the ending of my images sources string... i hope i worded that right. Anyway my current src's are reading: <img src="something/something/12345_m.jpg" /> I would like to change it to: <img src="something/something/12345_t.jpg" /> Any idea guy...

Ruby RegEx not matching valid expression

I have the following expression: ^\w(\s(+|-|\/|*)\s\w)*$ This simply looks to match a mathematical expression, where a user is prompted for terms separated by basic operators (ex: price + tax) The user may enter more than just 2 terms and one operator (ex: price + tax + moretax) I tested this expression in Rubular http://rubular.com/...

Regex javascript to match href

Hello, <u class="logout" href="/logout.php?h=970c9836674709e6dcdaadd094622fc5&t=1273295318" target="_top">Logout</u> That above is what I want to search for. I want to get h= and t= from that URL, or just get the entire url in href="" How would I do this with regex? ...

Get n Number of words using regex in Java

I have a section of a book, complete with punctuation, line breaks etc. and I want to be able to extract the first n words from the text, and divide that into 5 parts. Regex mystifies me. This is what I am trying. I creates an array of index size 0, with all the input text: public static String getNumberWords2(String s, int nWords){ ...

ruby enclose selected whole words in brackets

@string = "Sometimes some stupid people say some stupid words" @string.enclose_in_brackets("some") # => "Sometimes {some} stupid people say {some} stupid words" How should the method enclose_in_brackets look ? Please keep in mind, I want only enclose whole words, (I don't want "{Some}times {some} stupid....", the "sometimes" word shou...

How to determine that there is date in the string or not with different date format ?

I have a need of checking whether there is the date in the string or not. FUTIDX 26FEB2009 NIFTY 0 -- There is date in the string. FUTIDX MINIFTY 30 Jul 2009 -- There is date in the string. FUTSTK ONGC 27 Mar 2008 -- There is date in the string. How can I do that ? ...

Regex for date.

What should be the regex for matching date of any format like 26FEB2009 30 Jul 2009 27 Mar 2008 29/05/2008 27 Aug 2009 What should be the regular expression for that ? I have regex that matches with 26-Feb-2009 and 26 FEB 2009 with but not with 26FEB2009. So if any one know then please update it. (?:^|[^\d\w:])(?'day'\d{1,2}...

Substitute alt attribute with title attribute using sed

I have a PCRE regex that looks like this s/(<input.+?)alt(=".+?".*?>)/$1title$2/ Can anybody help me with making that work on sed? Eventually can anybody point me to some guide/blog post/whatever that explains differences between sed regex and PCRE? ...