regex

Having Trouble Renaming Files that Match with my RegEx

I have an app that "cleans" "dirty" filenames. "Dirty" filenames have #%&~+{} in their filenames. What my app does is see if they are a match for a RegEx pattern i have defined and then send it to a method called FileCleanUp where it "cleans" the file and replaces invalid chars with a "". However, i noticed while i was running this, t...

Removing a trailing Space from Regex Matched group

I'm using regular expression lib icucore via RegKit on the iPhone to replace a pattern in a large string. The Pattern i'm looking for looks some thing like this | hello world (P1)| I'm matching this pattern with the following regular expression \|((\w*|.| )+)\((\w\d+)\)\| This transforms the input string into 3 groups when a match...

How can I iterate over regular expression match variables in Perl?

I have a long regular expression that parses a text file into various match variables. For robustness, the match variables are likely to contain white space. I'd like to remove the whitespace in a systematic way by iterating over the match variables. For example, I have match variables $2 through $14 that contain some whitespace. I co...

Need help with some regular expressions in PHP

I need to port some simple eregi regular expressions to preg_match for PHP 5.3/6.0 compilance. Since I'm not too confident in my regular expression porting skills I need some help... #1 Old version: if( eregi('foo',$myVar) ) { $aresult = explode('/',stristr($myVar,'foo')); $aversion = explode(' ',$aresult[1]); } New version...

Java : replacing all URLs with anchor tags that aren't already in anchor tags

Hey, I'm trying to replace all non-anchor-tag-enclosed URLs within anchor-tag-enclosed URLs for a document. So given the string: I have two urls for google: <a href="http://www.google.com/"&gt;google&lt;/a&gt; and http://www.google.com/ I would like to replace it with this: I have two urls for google: <a href="http://www.google.com/...

Mysql count number of regex match per field

I'm trying to get mysql return the number of times a regex matches. something like: select 'aabbccaa' regexp 'a' should return 4 (4 matches of a), rather than just true (or 1). any way around it??? thanks !! ...

Replace part of an image url in ASP.NET using JQuery

Hi, I have a script which translates an image url to a path and works fine for an image fade on primary node navigation. The script below gives me: http://localhost/Bar/App_Themes/main/images/Beers-Faded.gif Once I navigate one node deeper it adds the application path to the url and the function fails: http://localhost/bar/Bar/App_T...

Inserting characters before whatever is on a line, for many lines

I have been looking at regular expressions to try and do this, but the most I can do is find the start of a line with ^, but not replace it. I can then find the first characters on a line to replace, but can not do it in such a way with keeping it intact. Unfortunately I don´t have access to a tool like cut since I am on a windows mach...

Performance and practice of lazy regex?

I read on the internet i should avoid lazy regex because of 'worse' performance and 'bad' practice. I never seen an example of either. I havent heard of an app that is CPU bound by its regular expression. Others say they 'learned' to avoid it but never mention why while one hinted it was because of usual side affects when turning on or o...

Python and Unicode Blocks for regex

Coming from the land of Perl, I can do something like the following to test the membership of a string in a particular unicode block: # test if string has any katakana script characters my $japanese = "カタカナ"; if ($japanese =~ /\p{InKatakana}/) { print "string has katakana" } I've read that Python does not support unicode blocks (tr...

regular expression and forward slash

i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" . Even using preg_quote($find,'/'), which escapes it, i still get the message: Unknown modifier 't' in /frontend.functions.php on line 71 If i print the find pattern, it shows ...

Regular Expression on web.config location path attribute (with parameters)

Is there any way of doing something like this? <location path="/(view|edit)post.aspx\?id=[7-9][0-9]+"> <system.web> <authorization> <allow roles="AdminPublishers"/> <deny users="*"/> </authorization> </system.web> </location> Authorization is just an example. I would like to be able to do other thin...

Problem matching regex pattern in Android

I am trying to search this string: ,"tt" : "ABC","r" : "+725.00","a" : "55.30", For: "r" : "725.00" And here is my current code: Pattern p = Pattern.compile("([r]\".:.\"[+|-][0-9]+.[0-9][0-9]\")"); Matcher m = p.matcher(raw_string); I've been trying multiple variations of the pattern, and a match is never found. A second set of...

REGEX - matching ** on at least one line in a textarea

Hi everyone, I have a textarea in which I need to validate that at least one line contains ** at the beginning of it. Examples Line 1 Line 2 Line 3 INVALID Line 1 **Line 2 Line 3 VALID **Line 1 Line 2 **Line 3 VALID Is this possible using Regex? Thanks in advance, Marko ...

Regex won't find '\u2028' unicode characters.

We're having a lot of trouble tracking down the source of \u2028 (Line Separator) in user submitted data which causes the 'unterminated string literal' error in Firefox. As a result, we're looking at filtering it out before submitting it to the server (and then the database). After extensive googling and reading of other people's probl...

PHP Regex Help for parsing String

I have a string such as the following: Are you looking for a quality real estate company? <s>Josh's real estate firm specializes in helping people find homes from [city][State].</s> <s>Josh's real estate company is a boutique real estate firm serving clients locally.</s> In [city][state] I am sure you know how difficult ...

Matching degree-based geographical coordinates with a regular expression

I'd like to be able to identify patterns of the form 28°44'30"N., 33°12'36"E. Here's what I have so far: use utf8; qr{ (?: \d{1,3} \s* ° \s* \d{1,2} \s* ' \s* \d{1,2} \s* " \s* [ENSW] \s* \.? \s* ,? \s* ){2} }x; Needless to say, this doesn't match. Does it have anything to do with the...

Visual Studio, Find and replace, regex

I am trying to replace all the #include "whatever.h" with #include <whatever.h> using find and replace functionality in Visual Studio 2005. I used the regex \#include \"[a-z\.h]+\" to find the include statement. But I am wondering how frame the replace regex. \#include \<[a-z\.h]+\> did not work and won't; it replaces the statement #inc...

Regular expression: matching the same character repeatedly

I was practicing regular expressions and attempted to write a regex which will detect "cay" and "cabby" and also "catty". I feel this is correct: ca(([bt])\1*)?y but on trying this on RegexBuddy, I see that it only matches "cay". Can anyone find the problem? thanks, Mishal ...

C# Regex Split - commas outside quotes

Hey, I got quite a lot of strings (segments of SQL code, actually) with the following format: ('ABCDEFG', 123542, 'XYZ 99,9') and i need to split this string, using C#, in order to get: 'ABCDEFG' 123542 'XYZ 99,9' I was originally using a simple Split(','), but since that comma inside the last parameter is causing havoc in the ou...