regex

Java Regex: Replacing full stops with spaces, or removing them if they are part of an abbreviation.

Hello, I have a series of text fields, which I need to clean of all full stops. The input text is company names, which sometimes contain abbreviations and sometimes full stops for other reasons. I would like to remove the full stops when the text is an abbreviation, otherwise, I would like to replace it with a space. I would define a...

Is there an Objective-c regex replace with callback/C# MatchEvaluator equivalent ?

I have a C# project I'm intending to port to Objective-C. From http://stackoverflow.com/questions/422138/regular-expressions-in-an-objective-c-cocoa-application, it looks like there's a confusing variety of Regex options but I can't see anything about a way of doing a replace with callback. That is, the equivalent of the C# MatchEvaluato...

How to match pattrns "begins with A or ends with B" with regular expression?

r'(^|^A)(\S+)(B$|$)' results to matches everything, which actually equals to ^\S$. How to write one matches "begins with A or ends with B, may both but not neither?" PS: I also need refer to group (\S+) in the substring module. Example: Match Aanything, anythingB, and refer anything group in the replace. ...

Simple regular expression question

I'm looking for a regular expression for one of my particular requirement explained below. I believe that this may be very simple & basic for the regex experts. A regular expression that matches one or more words in a line. Consider this line: QRYNUMB0007 = SELECT EMPLOYEEID, FIRSTNAME, LASTNAME, EMAIL, CITY, STATE, COUNTRY FROM EMPL...

Regex problem: Can't match a variable length pattern

I have a problem with regex, using preg_match_all(), to match something of a variable length. What I am trying to match is the traffic condition after the word 'Congestion' What I came up with is this regex pattern: Congestion\s*:\s*(?P<congestion>.*) It would however, extract the first instance all the way to the end of the entire ...

How do I split a till receipt using a Regular Expression?

The last time I used a regular expression was 2 years ago and even then it wasn't something I considered to be the simplest of things! Could anybody tell me how I would go about splitting this text into three groups (qty, name, price)? 1 Corn Dog 5.00 3 Corn Dog 15.00 @ 5.00 2 Diet Cola 4.00 ...

Catch first and last <li> inside php variable

echo $ul; // gives this code: <ul id="menu"> <li id="some_id" class="some_class">...</li> <li id="some_id" class="some_class">...</li> <li id="some_id" class="some_class">...</li> </ul> How to add some class for the first and the last <li>? Need a regex solution. echo $ul; should give (if we add class my_class for the last <li>): <...

mod_rewrite 301 redirect from old url to new codeigniter

Hi I have updated my website to now use the codeigniter framework my new urls are like the following example.com/index.php/home/page/page-title The old urls are example.com/index.php?option=com_content&view=article&id=249 Ideally I want to do a redirect for all links formatted in the old way to the new links but there are a lot of pag...

Refactoring sql into regexp - Microsoft Access

I'm not a pro with regexp and especially in this specific context. Any idea how to use a function to do a RegExp Replace and then calling it from the query in Microsoft Access? By the way, this query oddly enough doesn't work fully and maybe it's why this could use regexp. The idea is to match the three fields in the temp_table query:...

Regex PCRE: validate string that does not contains 3 or more consecutive digits

I've searched the questions but can't find an answer. I need a pattern that, used with php preg_match function, only match strings that does not contains 3 or more consecutive digits, e.g.: rrfefzef => TRUE rrfef12ze1 => TRUE rrfef1zef1 => TRUE rrf12efzef231 => FALSE rrf2341efzef231 => FALSE So far, I have wrote the...

eclipse - regex: replace multiple group

someText 1 2 3 4 moreText I would like to add a prefix before each digit. but using (\w+\R)(\d+\R)+(\w+) and \1prefix\2\3 will only prefix the last digit and erase the others. Is there a way to do it with a single regex or should i write a script on the side? ...

Percentage regex

Just a quick one here, does anyone know of a good regular expression for a percentage? Including 2 decimal places, i.e. 15.22%. I'm looking to put it inside a regularexpressionvalidator in ASP.NET. Thanks ...

Match several occurrences or zero (in this order) using regular expressions

Hello all, I want to match roman numbers using Groovy regular expressions (I have not tried this in Java but should be the same). I found an answer in this website in which someone suggested the following regex: /M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})/ The problem is that a expression like /V?I{0,3}/ is not greedy in ...

My Regular Expression will not Match Conditional Statement

Can anyone tell me why, even when my alert shows that my regular expression strings match, the if statement is not triggered? I have sample code below. Thanks in advance. $(document).ready(function () { $('div#primaryNavigation').find('a').each(function () { var pattern = /my-link1|my-link2|my-link3|my-link4/; var my...

Need help with javascript reg ex - how to remove part of a string

I need to remove everything after the last '/'. Source: /uploads/images/image1.jpg Result: /uploads/images/ How do I do this with regular expression? I've tried different solutions, but it's not working. I get NULL as a result. ...

regular expression for excluding IPs out of range

I am using google analytics and have a filter for one of the websites to exclude traffic that is not within an IP range, but I am creating a new profile, to track all that traffic within that IP range. This will allow me two different profiles, one to view all traffic that is on campus, and another to view all traffic excluding campus-tr...

help fixing up a regex - \r\n isn't being detected

Folks, I have method that returns true if all characters are "legal" and false if a single character is "illegal". The definition is below (legal = letters, numbers, and some characters like $, - , %, etc). I want a newline and/or carriage return character to be "illegal". However, the method below thinks that its legal. How can I f...

preg_match_all expression

I'm trying to extract src value from image tag using prag_match with perl pattern. I don't know where I'm making wrong but, I'm getting unwanted part as well. Here's how my pattern look like - preg_match_all('#src="http.+"#',$imagetag,$temp); $imagetag = "<img src="http://....." alt="build4.jpg" title="build4.jpg" width="320" height="2...

Regex for AMon:1

I'm a bit rubbish with Regex and was wondering if some kind person would be happy to assist! The format is: optionally 1, 2 , A or B Day Name, possibly short or full, eg Mon, Tuesday, Thursday, Fr Colon : or Space Integer The following are valid: EDIT: included "Mon:20" Mon:3, Tuesday:6, AWe:9, 2Fr:2, 2Wed 3,...

Filter Eclipse's "Open Call Hierarchy" to just my company/project

One of my favorite features of Eclipse is the ability to open a caller/callee hierarchy of a method. By default, the view shows calls to/from classes that are outside of my codebase... which I don't usually care about. There is an option to filter out specific package names I don't want, but I need to do the opposite... to filter out a...