regex

php regex - checking for two possible string literals values in an expression

I am using php preg_match and I have the original expression as: |(label\">Carried Price </span> £)((.)*?)( </div)| But I want to be able to able to be able to use the same basic expression but be able to search for Carried Price or Web Exclusive. I tried something like: |(label\">[Carried Price|Web Exclusive] </span> £)((.)*?)...

File system regular expression search tool

What is the best tool to make complex (multi-line) regular expression file contents searches with good reporting capabilities? I need to make a report over large Java/JSP code base and I have to make some charts afterward. Eclipse is rather good at searches, but it does not provide good report of what is found. It just shows the tree ...

Possible Root URLS

When validating URLs, I was wondering if the root could be setup like this: http://my.great.web.site.I.rule.com/ I guess the real question is, if someone wanted to buy a .com with the name "some.site", would the above example be possible? I was thinking something like that was out of the ordinary, and that the maximum would be someth...

replace any url's within a string of text, to clickable links with php

Say i have a string of text such as $text = "Hello world, be sure to visit http://whatever.com today"; how can i (probably using regex) insert the anchor tags for the link (showing the link itself as the link text) ? ...

Pattern (regex) based searching systems

I'm looking for a way to search through terabytes of data for patterns matching regexes. The implementation does need to support a lot of the finer capabilities of regexes, such as beginning and end of line data, full TR1 support (preferably with POSIX and/or PCRE support), and the like. We're effectively using this application to test...

In Perl, how can I capture a string of digits from a string containing carriage returns and line feeds?

I need to extract the text (characters and numbers) from a multiline string. Everything I have tried does not strip out the line feeds/carriage returns. Here is the string in question: "\r\n 50145395\r\n " In HEX it is: 0D 0A 20 20 20 20 20 20 20 20 35 30 31 34 35 33 39 35 0D 0A 20 20 20 20 I have tried the following: $s...

StackOverflowError with Checkstyle 4.4 RegExp check

Hello, Background: I'm using Checkstyle 4.4.2 with a RegExp checker module to detect when the file name in out java source headers do not match the file name of the class or interface in which they reside. This can happen when a developer copies a header from one class to another and does not modify the "File:" tag. The regular expres...

Get position of all matches in group

Hi Consider the following example: $target = 'Xa,a,aX'; $pattern = '/X((a),?)*X/'; $matches = array(); preg_match_all($pattern,$target,$matches,PREG_OFFSET_CAPTURE|PREG_PATTERN_ORDER); var_dump($matches); What it does is returning only the last 'a' in the series, but what I need is all the 'a's. Particularly, I need the position of ...

php only get the first occurrence of a word from an array.

Hello, I have an array of tags that I'm pulling from a database, I am exporting the tags out into a tag cloud. I'm stuck on getting only the first instance of the word. For example: $string = "test,test,tag,tag2,tag3"; $getTags = explode("," , $string); foreach ($getTags as $tag ){ echo($tag); } This would output the test...

regular expression search, omit lines

Hi I want to search something in the file which looks similar to this : Start Cycle report 1 report 2 report 3 report 4 End Cycle .... goes on and on.. I want to search for "Start Cycle" and then pull out report 1 and report 3 from it.. My regex looks something like this (Start Cycle .*\n)(.*\n)(.*\n)(.*\n) The above regex selec...

Determining if regexs cancel each other out

My task is to determine if a string should cause a command to be raised in my C# command processor, this being configurable at runtime. I have two collections of regexes. For the first collection 'EnabledPatterns' the command is enabled if any one of the patterns matches the command string. For the second 'DisabledPatterns' the command...

How can I get part of regex match as a variable in python?

In Perl it is possible to do something like this (I hope the syntax is right...): $string =~ m/lalala(I want this part)lalala/; $whatIWant = $1; I want to do the same in Python and get the text inside the parenthesis in a string like $1. ...

How do I look for “ and ” in php using preg_match?

I've been using "/x{201C}/u" and "/x{201D}/u" to match them, but there's no result. Am I doing something wrong?? ...

Double plusses in regex

I have seen several regular expressions that have two plusses in a row. What exactly does this mean? One or more of one or more of the pattern. If the pattern matches in the first place, why would the second match be necessary? Examples: [a-zA-Z0-9_]++ [^/.,;?]++ ...

GREP: How to search for a value but at the same time exclude some matches

I need a way to simplify this command: grep 'SEARCHTERM' server.log | grep -v 'PHHIABFFH' | grep -v 'Stats' It should find all the lines including SEARCHTERM but exclude if one of the SEARCHTERM lines includes PHHIABFFH or Stats. ...

Java: RegEx Problem (using the '.' all character symbol)

I have some document stored as a large String. In the String I have some inline XML tags and I want to get out the words inbetween the tags. The documents may also contain HTML tags, as the documents are often web sites. Example Document: "< tr > My name is < b >< PERSON >Bobby< /PERSON >< /b >, I live in the USA." Current RegEx: ...

How can I match IPv6 addresses with a Perl regex?

So I need to match an ipv6 address which may or may not have a mask. Unfortunately I can't just use a library to parse the string. The mask bit is easy enough, in this case: (?:\/\d{1,3})?$/ The hard part is the different formats of an ipv6 address. It needs to match ::beef, beef::, beef::beef, etc. An update: I'm almost there.. /^...

How to find a string between two other strings with regex?

In a sort-of-duplicate, the answer was : \[start\](.*?)\[end\] but that yields the [start] and [end] tag too. How do you omit them? E.g.: f("[somestartstring]result[someendstring]") == "result" UPDATE: the suggested answers are not working. My code is: printfn "%s" (Regex.Match(@"[start]result[end]", "\\...

Regex: match SQL PRINT blocks with quoted text in it

Hi all, I got the following text: PRINT CONVERT(NVARCHAR, CURRENT_TIMESTAMP, 111) + ' ' + CONVERT(NVARCHAR, CURRENT_TIMESTAMP, 108) + ' -Test Mode : ' + (CASE WHEN @turbo_mode_ind = 1 THEN 'some text ''test'' some more text.' ELSE 'an...

Python regular expression matching a multiline block of text but not replacing it

Ok so i have this piece of code: def findNReplaceRegExp(file_name, regexp, replaceString, verbose=True, confirmationNeeded=True): '''Replaces the oldString with the replaceString in the file given,\ returns the number of replaces ''' # initialize local variables cregexp = re.compile(regexp, re.MULTILINE | re.DOTALL) somet...