regex

How to correctly extract data with Regular Expressions

Hi, i'm facing regulars expressions for the first time and i need to extract some data from this report (a txt file with formatting info): \n10: Vikelis M, Rapoport AM. Role of antiepileptic drugs as preventive agents for \nmigraine. CNS Drugs. 2010 Jan 1;24(1):21-33. doi:\n10.2165/11310970-000000000-00000. Review. PubMed P...

Apache LocationMatch regex with subdomain

I'm trying to use LocationMatch to match an URL in a website's second-level subdomain but not in it's third-level subdomain. This is because I want to password protect some URLs at that level. eg. level2.domain.com/some/url should match but not level3.level2.domain.com/some/url Than I would apply the necessary directives to password pr...

How can I convert this positive lookbehind to a lookahead assertion?

I'm using the following regular expression in my code to validate option symbols: ^([A-Za-z]{1,5}\d? +\b(?<=^.{6}))[0-9]{6}[CcPp][0-9]{8}$ If you notice, I'm using a negative lookbehind assertion to confirm that the previous match was only 6 characters. However, JScript Regex apparently doesn't support lookbehinds but it does support...

How to extract a value from a string using regex and a shell?

I am in shell and I have this string: 12 BBQ ,45 rofl, 89 lol Using the regexp: \d+ (?=rofl), I want 45 as a result. Is it correct to use regex to extract data from a string? The best I have done is to highlight the value in some of the online regex editor. Most of the time it remove the value from my string. I am investigating expr, ...

php ereg_replace in php 5.3

Hi guys, So I am trying to create this function which replaces a certain symbol with something else. I was going to use ereg_replace but I saw that it has been deprecated in 5.3. Can you guys give me suggestion on what to use for this purpose. To be more specific, I want to create a function that parses in an email which replaces a cer...

Having some trouble with Regex

Ok, so I have this: $fromArray = array( "/(\[color=)(.+)(\])/", "(\[\/color\])"); $toArray = array( "<span style=\"color:\\2\">", "</span>"); What that's supposed to do it match all [color= to . I'm running that, but this is what the source outputs: <span style="color:red]RED<b>BOLD</b>RED[/color"> When I try to run [color=red...

What's the difference between "groups" and "captures" in .NET regular expressions?

I'm a little fuzzy on what the difference between a "group" and a "capture" are when it comes to .NET's regular expression language. Consider the following C# code: MatchCollection matches = Regex.Matches("{Q}", @"^\{([A-Z])\}$"); I expect this to result in a single capture for the letter 'Q', but if I print the properties of the ret...

Using <string>.split (and a regular expression) to check for inner quotes

I'm implementing a search in my website, and would like to support searching for exact phrases. I want to end up with an array of terms to search for; here are some examples: "foobar \"your mom\" bar foo" => ["foobar", "your mom", "bar", "foo"] "ruby rails'test course''test lesson'asdf" => ["ruby", "rails", "test course", "test lesson"...

How to use regex to replace URLs with an HTML link in Qt?

How do I use QString::replace to detect URLs in a string and replace them with an HTML link, like so... [...].replace(QRegExp("???"), "<a href=\"\\1\">\\1</a>") What should the argument to QRegExp be? The end of a URL should be denoted by the occurrence of a whitespace character (such as space, \r or \n) or the end of the string. Th...

How to do perl inline regex without setting to a variable?

Normally if you wish to change a variable with regex you do this: $string =~ s/matchCase/changeCase/; But is there a way to simply do the replace inline without setting it back to the variable? I wish to use it in something like this: my $name="jason"; print "Your name without spaces is: " $name => (/\s+/''/g); Something like tha...

PHP: preg_split

Hey guys, I need help on regular expression here. I want PHP to be able to splits a string in sections of arrays such that a substring enclosed by <%me %> will be in its own slot. So for example, Hi there how are <%me date(); %> => {"Hi there how are ", "<%me date(); %>} Hi there how are you<%me date(); %> => {"Hi there how are you"...

Help Using RegexIterator in PHP

I have yet to find a good example of how to use the php RegexIterator to recursively traverse a directory. The end result would be I want to specify a directory and find all files in it with some given extensions. Say for example only html/php extensions. Furthermore, I want to filter out folders such of the type .Trash-0, .Trash-50...

Python Regex Question

I have an end tag followed by a carriage return line feed (x0Dx0A) followd by one or more tabs (x09) followed by a new start tag . Something like this: </tag1>x0Dx0Ax09x09x09<tag2> or </tag1>x0Dx0Ax09x09x09x09x09<tag2> What Python regex should I use to replace it with something like this: </tag1><tag3>content</tag3><tag2> Than...

Help on Regular Expression problem

Hi, i wonder if it's possible to make a RegEx for the following data pattern: '152: Ashkenazi A, Benlifer A, Korenblit J, Silberstein SD.' string = '152: Ashkenazi A, Benlifer A, Korenblit J, Silberstein SD.' I am using this Regular Expression (Using Python's re module) to extract these names: re.findall(r'(\d+): (.+), (.+), (.+), (...

grab CSS value with Regex

Hi There I am hoping that someone can help me with this regex, I need to grab test2 and everything between { } .test1 {font-family: Arial, Helvetica, sans-serif; color: #42bf32; font-size: 14px; } .test2 {font-family: Arial, Helvetica, sans-serif; color: #42bf32; font-size: 14px; } .test3 {font-family: Arial, Helvetica, sans-serif;...

Auto-clean Log Formats

I've run into several different situations where I need to implement a "log cleanup" regex. I've had to re-implement a couple times, but the basic variant is this: The Original (23:59:59) Username says: user inputted text (00:00:13) Username user inputted action (00:01:42) Username says: user inputted text (00:02:13) Username says: use...

Searching for ip addresses using wingrep

I'm using WinGrep to search for IP Addresses in a .txt file, but i can't figure out how to get it to use a regular expression to search. does anyone have any experience with this? ...

Basic Regex information

Where can I find basic information on Regex? My textbook does not explain it very well. ...

regex to get the domain name from a url in ruby

I trying to construct a regex to extract a domain given a url . for eg. http://www.abc.google.com/ http://abc.google.com/ https://www.abc.google.com/ http://abc.google.com/ should give abc.google.com any hellp verymuch appreciated. Thanks ...

Java Statement Pattern Matching

Hello, I am trying to write a simple template engine to parse if statements. <{if $value == true}> say hello <{/if}> I have written working code However, If I have multiple if statements in the file I am parsing then if grabs only the first and last if statement. For example. <{if $value1 == true}> say hello <{/if}> ... <{if...