regex

Empty replacement result, when regex doesnt match

Regex.Replace("some big text", "^.+(big).+$", "$1"); // "big" Regex.Replace("some small text", "^.+(big).+$", "$1"); // "some small text", but i need here empty string I need to select a value from the string. It's ok, when the string matches the pattern. But when the string doesn't match, there is an original string in replacement res...

Java : replace regexp with processed match

Let's say I have the following string : String in = "A xx1 B xx2 C xx3 D"; I want the result : String out = "A 1 B 4 C 9 D"; I would like to do it a way resembling the most : String out = in.replaceAll(in, "xx\\d", new StringProcessor(){ public String process(String match){ int num = Integer.parseInt(matc...

Does Ruby support conditional regular expressions.

Just a language feature question, I know there's plenty of ways to do this outside of regexes (or with multiple regexes). Does ruby support conditional regular expressions? Basically, an IF-THEN-ELSE branch inside a regular expression, where the predicate for the IF is the presence (or absense) of a captured group in the expression. I...

java generate regular expression from localized NumberFormat

Is there any clean way to generate a regular expression that will match values formatted with a locale-configured java NumberFormat? Or some library that will do so? This is in a web-based app & I want to pass the regex out to the jsp page for javascript validation on numeric fields. Locale varies on a per-user basis & I'd like to not...

I want to filter out the foregin links from my blog post, can some one help with me the regular expressions ?

I have blog data like: This is foreign <a href="xyz.com">link</a>, this is my site's <a href="mysite.com">link</a> and so on. What I want is to do is filter the links of foreign sites, i.e "<a href="xyz.com">link</a>". So that my final output is: This is foreign link, this is my site's <a href="mysite.com">link</a> and so on. I tri...

Regex Question: how do I replace a single space with a newline in VI

Regex Question: how do I replace a single space with a newline in VI. ...

C#'s regex not working like I want it too

I have an input string like this: \pard\nowidctlpar\qj\b0\scaps This Agreement\scaps0 is made and entered into this date, \{#DATEAGREEMENT#\} , by and between [removed] (\ldblquote [removed]\rdblquote ), and its successors and/or assigns, with address at [removed], and \{#TXTPLAINTIFF#\} , (\ldblquote Plaintiff\rdbl...

Need help with parsing sql in java

I have the below code that splits the sql statement and give its indices for the columns. String sql = "INSERT INTO Table1(SSN, EMPID) VALUES (?,?)"; public static List<Object[]> indices(String stmt) { List<Object[]> list = new ArrayList<Object[]>(); String variables[] = null; try { variables = ...

Regex for matching all words between a set of curly braces

A simple question for most regex experts I know, but I'm trying to return all matches for the words between some curly braces in a sentence; however Ruby is only returning a single match, and I cannot figure out why exactly. I'm using this example sentence: sentence = hello {name} is {thing} with this regex to try and return both "...

Regular expression lookbehind problem

Hi folks, I use (?<!value=\")##(.*)## to match string like ##MyString## that's not in the form of: <input type="text" value="##MyString##"> This works for the above form, but not for this: (It still matches, should not match) <input type="text" value="Here is my ##MyString## coming.."> I tried: (?<!value=\").*##(.*)## w...

how to use regex on in a find function in jquery

I have the following statement: if ($(this).find("option[text='My Cool Option1']").is(":selected")) //do something basically I have a combobox with many options. I want to do something for options that start with My Cool Option<any number> above code works for only one option My Cool Option1...but how do I make it work for say My C...

Java Regex Match Error

I'm trying the following segment to no avail: public class test { public static void main(String args[] ){ String password = "s8bgBQYPmUaNjkToXCJLAwAA"; System.out.println( Pattern.matches("[0-9]", password )); } } I would expect that to work since I'm just looking for match of any digit to suffice the regex ...

Why is this regex behaving like this?

I have a regular expression here, and I want it to return only users, comments, and posts. However, even though I have \s, whitespace, in my negative character set, it still is extracting a match from it. Why is this? ...

human's height,weight validation in asp.net

I am trying to make a height (person height) and weight validation. Height should look something like this: 5'11" Anything in any other different format should show up as wrong. What should I use for ValidationExpression? and onee more question "[10-200].(1[0-1]|\d)" is this correct for weight validation ...

How do I remove all question marks and a minus signs using a regex?

I can get it to remove all the question marks with the code below: preg_replace('/(\?+)/', '', $string) No matter what I seem to do I can't get it to also remove all the minus signs as well. Everything I try just breaks the whole regex. ...

Using a regex, how can I delete some colons and replace others with spaces?

It is necessary regexp to replace in a line of a colon with blanks, excepting situations where a colon the first and (or) last symbol - them is simply deleted. Example1 "6:206:НР" -> "6 206 НР" Example2 ":206:" -> "206" ...

Ruby regular expression using gsub

Hi I'm new to Ruby and regular expressions. I'm trying to use a regular expression to remove any zeros from the month or day in a date formatted like "02/02/1980" => "2/2/1980" def m_d_y strftime('%m/%d/%Y').gsub(/0?(\d{1})\/0?(\d{1})\//, $1 + "/" + $2 + "/" ) end What is wrong with this regular expression? Thanks. ...

Why does Perl replace my string with "1"?

I have the following code: #$domain = domainname.co.uk #$root = public_html #$webpage = domainname.co.uk/foo/bar/foobar.html my $string = ($webpage =~ s/^$domain//g); my $linkFromRoot = $dbh->quote($root . $string); Usualy this works fine but for some reason the output is "public_html 1" instead of "public_html/foo/bar/foobar.html". ...

Python regex for reading CSV-like rows

I want to parse incoming CSV-like rows of data. Values are separated with commas (and there could be leading and trailing whitespaces around commas), and can be quoted either with ' or with ". For example - this is a valid row: data1, data2 ,"data3'''", 'data4""',,,data5, but this one is malformed: data1, data2, da"ta3", 'd...

Regex to match the first file in a rar archive file set

How do I do this? I've seen a solution not using a single regex for ruby becauase ruby doesn't support loookaround assertions. But is it possible in c#? [Test] public void RarArchiveFirstFileNameShouldMatch() { var regex = new Regex(@"\.(rar|001)$", RegexOptions.IgnoreCase | RegexOptions.Singleline); Assert.That(regex.IsMatch("f...