regex

Java Counting # of occurrences of a word in a string

I have a large text file I am reading from and I need to find out how many times some words come up. For example, the word the. I'm doing this line by line each line is a string. I need to make sure that I only count legit the's--the the in other would not count. This means I know I need to use regular expressions in some way. What ...

Conditional Regular Expression testing of a CSV

I am doing some client side validation in ASP.NET MVC and I found myself trying to do conditional validation on a set of items (ie, if the checkbox is checked then validate and visa versa). This was problematic, to say the least. To get around this, I figured that I could "cheat" by having a hidden element that would contain all of the ...

Why does findstr not handle case properly (in some circumstances)?

While writing some recent scripts in cmd.exe, I had a need to use findstr with regular expressions - customer required standard cmd.exe commands (no GnuWin32 nor Cygwin nor VBS nor Powershell). I just wanted to know if a variable contained any upper-case characters and attempted to use: > set myvar=abc > echo %myvar%|findstr /r "[A-Z]"...

how to read string part in java

Hello everyone, I have this string : <meis xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" uri="localhost/naro-nei" onded="flpSW531213" identi="lemenia" id="75" lastStop="bendi" xsi:noNamespaceSchemaLocation="http://localhost/xsd/postat.xsd xsd/postat.xsd"> How can I get lastStop property value in JAVA? This regex worked when t...

Zend/PHP: How to remove all leading 0s from string ?

I have a string which contains only numbers. Now I want to remove all leading 0s from that string For example: input: 000000001230 output: 1230 input: 01000 output: 1000 Is there any function in PHP/Zend for this? Thanks ...

Perl regex extract parts of string with multiple condition

What's the single regex that enables me to capture all the text that goes after are genes and is gene from this text The closest human genes of best are genes A B C The closest human gene of best is gene A Hence I hope to extract $1 that contain A B C A Tried this but fail: $line =~ /The closest .* gene[s] (.*)$/; ...

Perl like regex in Python

In Perl I would do something like this for taking different fields in a regexp, separating different fields by () and getting them using $ foreach $line (@lines) { $line =~ m/(.*?):([^-]*)-(.*)/; $field_1 = $1 $field_2 = $2 $field_3 = $3 } How could I do something like this in Python? ...

How to negate the whole regex?

I have a regex, for example (ma|(t){1}). It matches ma and t and doesn't match bla. I want to negate the regex, thus it must match bla and not ma and t, by adding something to this regex. I know I can write bla, the actual regex is however more complex. ...

php regex for strong password validation

Hello, I've seen around the web the following regex (?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$ which validates only if the string: * contain at least (1) upper case letter * contain at least (1) lower case letter * contain at least (1) number or special character * contain at least (8) characters ...

preg_replace to capitalize a letter after a quote

I have names like this: $str = 'JAMES "JIMMY" SMITH' I run strtolower, then ucwords, which returns this: $proper_str = 'James "jimmy" Smith' I'd like to capitalize the second letter of words in which the first letter is a double quote. Here's the regexp. It appears strtoupper is not working - the regexp simply returns the unchang...

Why do I get extra, unexpected results with my ack regex?

I'm finally learning regexps and training with ack. I believe this uses Perl regexp. I want to match all lines where the first non-blank characters are if (<word> !, with any number of spaces in between the elements. This is what I came up with: ^[ \t]*if *\(\w+ *! It only nearly worked. ^[ \t]* is wrong, since it matches one or non...

Convert regular expression to CFG

How can I convert some regular language to its equivalent Context Free Grammar? Whether the DFA corresponding to that regular expression is required to be constructed or is there some rule for the above conversion? For example, considering the following regular expression 01+10(11)* How can I describe the grammar corresponding to...

Python : Small Regex problem

Hi, when I try to extract this video ID (AIiMa2Fe-ZQ) with a regex expression, I can't get the dash an all the letters after. Someone can help me please? Thanks >>> id = re.search('(?<=\?v\=)\w+', 'http://www.youtube.com/watch?v=AIiMa2Fe-ZQ') >>> print id.group(0) >>> AIiMa2Fe ...

Regex question in C#

hi how to remove only one char (") if there two("") from the string in C# (Regex ) ex.: 123"43""343"54"" ==> 123"43"343"54" "abc""def"gh""i ==> "abc"def"gh"i thank's in advance ...

how to remove char (") from the begin and the end of a string ?

hi how to remove char (") from the begin and the end of a string ? ex: "1234"567" ==> 1234"567 thank's in advance ...

String to array or Array to string tips on formats, etc

hi, first of all thanks for taking your time! I'm a junior Dev, working with PHP + mysql. My issue: I'm saving data from a form to my database. From this form, there's only need to save the contacts: Name, phone number, address. But, it would be nice to have a small reference to the user answers. Let's say for each question we've go...

Python regexp to match e-mail against domain names

I'm looking for the "perfect" regexp's to validate if an e-mail belongs to a domain name (including sub-domains), for example: www.domain.com : [email protected] sub.domain.com : [email protected] domain2.com : [email protected] ...

Nested Groups in Regex

I'm constructing a regex that is looking for dates. I would like to return the date found and the sentence it was found in. In the code below, the strings on either side of date_string should check for the conditions of a sentence. For your sake, I've omitted the regex for date_string - sufficed to say, it works for picking out dates. Wh...

Make regular expression case insensitive

Given this regular expression: "^[0-9]*\s*(lbs|kg|kgs)$" how do I make it case insensitive? I am trying to use this in a .net regular expression validator, so I need to specify case insensitivity in the pattern. I can not use the RegexOptions programatically because I am specifying the regular expression in a RegularExpressionValidato...

How to match multiple lines with Regex in C#?

I have the following text: --------------030805090908050805080502 Content-Type: image/jpeg Content-Transfer-Encoding: base64 Content-ID: <[email protected]> /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAA /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAA QBQH/9k= --...