regex

Limited string replacement using regex?

Is it possible to use regex to only replace X number of occurrences of a particular string? For example, if I have the word 'lion' in a string 10 times, could I use regex to only replace the first 6 occurences instead of all of them? ...

PHP preg_replace making regex optional?

Hi, I have some content that I am trying to parse... I have html and with in the html I want to replace all my img tags with a custom string. Now one of the problems I have is that some content that comes in: the image tags is between a anchor. ex. <a href="link"><img></a> The following code I have works...but I want it to be option...

Is there a way to overload the regex binding operator `=~` in Perl?

I am working on a small DSL that uses the nomethod fallback for overloading to capture the operators used on the overloaded values. This is similar to the function of the symbolic calculator described in overload's documentation. This works fine for the standard comparison operators, but consider the following: my $ret = $overloaded =...

Add extra class for <li>

$string = '<ul> <li id="34334" class="some_class"><a href="/stack/">Text</a></li> <li id="someid" class="more_class"><a href="/overflow/">Text</a></li> </ul>'; What I need (actually don't know how to do, please help): We must check <a> inside each <li> If href of <a> == /stack/, then add extra class current for parent <li> ...

Regex: How can I remove whitespace within a style attribute only?

Hi, for the last hour I have been trying to figure this out myself but I am just not having any success and thought maybe you could help. Basically I am having a html email document that has a lot style attributes for inline styling of elements that look somewhat like <th rowspan="10" style="font-weight: normal; vertical-align: top; te...

What does ?: do in regex

I have a regex that looks like this /^(?:\w+\s)*(\w+)$*/ What is the ?:? ...

Check if line in richtextbox contains numbers.

I have a list of strings in my richtextbox. I need a code to check if there are numbers in the first line, if there is then proceed with the rest of my code, else delete first line. ...

use php, grep and regex to search and replace lines of code in file

I have a php file that can read the contents of other files perfectly and return them as a string. $contents = $file->read(); // return as string. i need to be able to search and replace certain lines lines that begin with $this->Session->setFlash and end with , true)); must be replaced with lines that begin with $this->Session->s...

Mixing regex and shell wildcards

I have a python script that reads from a config file. The config file is going to contain some user defined regex patterns. However, I was thinking I'd like to let the user use either full regex patterns, OR shell wildcards. So I should be able to interpret both *.txt as well as .*\.txt$ correctly. So those 2 should be equivalent. How...

how to write a regex for this expression?

url1 = http://xyz.com/abc url2 = http://xyz.com//abc I want to write a regex that validate both url1 and url2 ...

Regular Expression

Hi I need write a regular expression for RegularExpressionValidator ASP.NET Web Controls. The regular expression should ALLOW all alphabetic characters but not number and special characters (example: |!"£$%&/(). Any idea how to do it? thanks ...

Will both of these Regex terms find the same matches using C# isMatch() method?

Hi, Will a regex created with the following terms match the same results? "canon| eos" "1d" and canon|eos 1d Now I do not want to match the quotation marks (") in the string. Will the fact they are in there make a difference. Will the first term match "canon but not canon? Am I right in what I am saying? ...

Regular Expression (Python) to extract strings of text from inside of < and > - e.g. <stringone><string-two> etc...

I'm currently playing with the Stack Overflow data dumps and am trying to construct (what I imagine is) a simple regular expression to extract tag names from inside of < and > characters. So, for each question, I have a list of one or more tags like <tagone><tag-two>...<tag-n> and am trying to extract just a list of tag names. Here are...

How can I use Perl regexp characters when inside a bash script?

I would like a command line function that I can run on any file to change the include("myinc.inc"); PHP statement to include 'myfile.inc'; I have made a start by adding the following to my ~/.bashrc file: function makestandard() { perl -p -i -e 's/include\("([\w\.]+)"\)/include '$1'/g' $* } I source ~/.bashrc; and run the command ...

Boost xpressive ! operator not working

I just started using Boost::xpressive and find it an excellent library... I went through the documentation and tried to use the ! operator (zero or one) but it doesn't compile (VS2008). I want to match a sip address which may or may not start with "sip:" #include <iostream> #include <boost/xpressive/xpressive.hpp> using namespace boos...

Regex to validate several ranges of values (.NET)

Hello guys, I have the option to use a regex to validate some values and I would like to know the best way to do it. I have several ranges (not in the same regex/validation) such as 1-9 (this is easy :P), and: 1-99 1-999 1-9999 Also, I need to check for leading zeros, so, 0432 is a possible match. Any ideas? I know that Regex might...

How to replace &nbsp; to space?

Content is &nbsp;&nbsp;&nbsp;&nbsp;Hello World. <a&nbsp;href="#"&nbsp;target=_blank>hello&nbsp;World</a> How to replace the &nbsp; in html code and keep the other &nbsp; in the text. ...

Regular expression for checking the range of numeric values

I want to have a range between 0 to 65536 , what would be the regular expression for that? ...

RegEx a RegEx match

Hey there, I'm having trouble building the correct regex for my string. What I want to do is get all entities from my string; they start and end with '. The entities are identifiable by an amount of numbers and a # in front. However, entities (in this case a phone number starting with #) that don't start or end with ' should not be matc...

Regex replace all except of this string

Hi ! I have a XAML document and I want to select all texts with Regex with this form: Default=xyz} I wrote for it this very simple regex and it works: Default=.+} Now, how do I exactly the opposite? I want to delete all other text than this in the document. I'm using Notepad++. Thanks ...