regex

[Ruby] How to match/extract domain name from messy user input?

There is a form field where users should input domain names in the form of "google.com". However, taking into consideration confused users, I want to be able to clean the input to the exact form of "google.com" in case they type in the following cases: http://www.google.com http://google.com google.com/blah www.google.com ..and other i...

Java equivalent of JavaScript's String.match()

Hi As the title says, what is the Java equivalent of JavaScript's String.match() I need to get an array or a list of all matches Example: var str = 'The quick brown fox jumps over the lazy dog'; console.log(str.match(/e/gim)); gives ["e", "e", "e"] http://www.w3schools.com/jsref/jsref%5Fmatch.asp regards Jon ...

How do I retrieve the data between "_id=" and "&"?

How do I parse string "7c23a12f0cffa6cf2fac0baf8eacf4c1" from a file .. I am trying to retrieve the data between _id= and & example file: 4593733f4ab534f0001ecbe20000b3e9/cgi-bin/rsspipes/dispatch?Alternative=10...

How to find a URL from a content by PHP?

need a simply preg_match, which will find "c.aspx" (without quotes) in the content if it finds, it will return the whole url. As a example $content = '<div>[4]<a href="/m/c.aspx?mt=01_9310ba801f1255e02e411d8a7ed53ef95235165ee4fb0226f9644d439c11039f%7c8acc31aea5ad3998&amp;n=783622212">New message</a><br/>'; now it should preg_match "c....

Regular expression to replace an <a> with respective <img>

I'm looking for a PHP preg_replace() solution find links to images and replace them with respective image tags. Find: <a href="http://www.domain.tld/any/valid/path/to/imagefile.ext"&gt;This will be ignored.</a> Replace with: <img src="http://www.domain.tld/any/valid/path/to/imagefile.ext" alt="imagefile" /> Where the protocol MUST...

What are some of the most useful regular expressions for programmers?

I am new to regular expressions and have just started learning some. I was wondering what are some of the most commonly used regular expressions by the programmers. Put it in another way, I would like to know what are the regular expressions most useful for? How can they help me in my every day tasks? I would prefer to know regular expre...

C# Split a string into equal chunks each of size 4

E.g. Input string str = "1111222233334444"; return value ArrayList A where A[0] = "1111", A[1] = "2222", etc. Use of Linq or reg ex would be good. ...

Match number at the end of the string

Hello there, Given the following string how can I match the entire number at the end of it? $string = "Conacu P PPL Europe/Bucharest 680979"; I have to tell that the lenght of the string is not constant. My language of choice is PHP. Thanks. ...

Regular Expression works at regexlib but not in C# code

Need some help, I have a regular expression that appears to work just fine when I put the pattern and string to parse into regexlib's tester. However, when I put it into C#, the same does not happen, no match. Here is my match pattern, have tried both: string regPattern = "\\{\\$([^\\$\\}]+)\\$\\}"; My string to parse comes from a d...

Should I use mod_rewrite for my site's URLs?

My site currently handles URL's like this... /?p=home /?p=profile&userid=1 /?p=users.online /?p=users.online&page=23 /?p=mail.inbox /?p=mail.inbox&page=12 ... and so on, there is probably at least 120-150 different pages, on my site a page is built like this, index.php includes a main config file which then includes func...

PHP regex matching recursively

Hi I'm trying to match a certain set of tags in a template file. I however want the tags to be able to be nested in itself. My regex is the following: (with /s) <!-- START (.*?) -->(.*?)<!-- END \\1 --> Tag example: <!-- START yList --> y:{yList:NUM} | <!-- START xList --> x:{xList:NUM} <!-- END xList --> <!-- CARET x...

Is this possible with regex

I am wanting to use mod-rewrite for cleaner URL's across my whole site which is going to be really hard, I will have to most likey rename many files/structure. Would this be possible though if a page currently is like this www.domain.com/?p=users.online&page=23 to re-write it as /users/online/page/23 but then also work wh...

How can I make this backlink checker regex better, its missing some sites

<? $mysite = ('websiteurl');?> <? echo $mysite; ?> Links not found <? $time_limit = 3600; set_time_limit($time_limit); include_once("myconnect.php"); $sql0="select * from trade where 1 "; $sql0=$sql0." order by a1 asc"; $query=mysql_query($sql0); $cnt=1; while ( ($rs_query=mysql_fetch_array($query)) ) { if($cnt%2<...

Is there a better way to do this regex?

I finally figured out a good/easy way to make clean URLs with regex on my site in this format below, however it will require a very large .htaccess file, I know from the post on here that it is supposed to not be to bad on performance to use mod_rewrite but I have never really seen it used where the way I am, with a seperate entry for al...

How to split a string by multiple delimiters in PHP?

"something here ; and there, oh,that's all!" I want to split it by ; and , so after processing should get: something here and there oh that's all! ...

How to match a decimal letter and blank in vim?

Hi Guys, I need to change 1 A 2 B 3 C 4 D to A B C D which means the decimal letter at the begining of every line and the following one or more blank should be deleted . I'm only familiar with Reqex in Perl, so I try to use :%s/^\d\s+// to solve my problem, but it does not work. so does anyone of you can tell me how to get ...

regular expression that matches a string which comprises of only specific letters

Hi guys, I've tried several regex combinations to figure out this, but some or the condition fails, I have an input string, that could only contain a given set of defined characters lets say A , B or C in it. how do I match for something like this? ABBBCCC -- isMatch True AAASDFDCCC -- isMatch false ps. I'm using C# ...

Increment digit value in String

So, i have some String with digits and another symbols, and i want to increment the value of each digit at 1. For example: "test1check2" from this String i want to recieve "test2check3". And can i make this only with method "replaceAll"? (i.replaceAll("\d", ...) something like that)?, without to use methods such like indexOf, charAt......

JavaScript: split doesn't work in IE???

Is there a reason why the following piece of code doesn't work in IE? While with FF and other sane browsers it splits the string by the given expression, in IE it simply doesn't work. var str = "abc<font id=\"something\">def</font>gh"; alert(str.split(/(\<.*?\>|.)/).length); Thank you. ...

How to add / to the end of a URL using IIS7 Rewite rules

Hi Guys I need to add a trailing / to a url if it doesn't have one or isn't a file so http://www.ddd.com/dasdas becomes http://www.ddd.com/dasdas/ But I don't what to just add slash the URl as this will end up with filename like this style.css/ So I need a piece of Regex that I can put into the IIS 7 rewrite engeine to append when...