regex

How to make dot match newline characters using regular expressions

I have a string that contains normal characters, white charsets and newline characters between and . This regular expression doesn't work: /<div>(.*)<\/div>. It is because .* doesn't match newline characters. My question is, how to do this? ...

how to use Pattern matcher in java?

lets say the string is <title>xyz</title> I want to extract the xyz out of the string. I used: Pattern titlePattern = Pattern.compile("&lttitle&gt\\s*(.+?)\\s*&lt/title&gt"); Matcher titleMatcher = titlePattern.matcher(line); String title=titleMatcher.group(1)); but I am getting an error for titlePattern.matcher(line); ...

Gruber’s URL Regular Expression in Python

How do I rewrite this new way to recognise addresses to work in Python? \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))) ...

Match all URLs in string and return in array in JavaScript

For example, I have the following string: var string = 'watch this video http://vimeo.com/8122132 and then see this picture http://www.flickr.com/photos/pmorgan/32606683/'; I wish to find all the valid URLs and place them in an array, done in JavaScript (and jQuery), so in this case: url[0] = http://vimeo.com/8122132 url[1] = http://...

Regex in javascript workin with Cyrillic (Russian) set

Is it possilbe to work with Russian characters, in javascript's regex? Maybe the use of \p{Cyrillic}? If yes, please provide a basic example of usage. The example: var str1 = "абв прв фву"; var regexp = new RegExp("[вф]\\b", "g"); alert(str1.replace(regexp, "X")); I expect to get: абX прX ...

preg_split commas not inside parenthesis

Test string: Organic whole wheat bread, Monterey Jack Cheese (milk, cheese culture, salt), Hormel Natural Ham (salt, turbinado sugar, lactic acid (not from milk) Desired output: Array ( [0] => Organic whole wheat bread [1] => Monterey Jack Cheese [2] => Hormel Natural Ham ) I don't mind if the sub-in...

Problem with MySQL storage of a Craigslist parse

I'm using MagpieRSS to parse a Craigslist feed. The "title" field is: ***BUYING ALL BRAND NEW BLACKBERRY IN ANY QUANTITY BOLD~JAVELLIN~ONYX (Gramercy) $100000 and I'm using if( preg_match( "/\(*\)*\d+$/", $title, $matches ) ) to figure out the price. $matches[0] should have the price, if I'm not mistaken. However, when I put ...

Regex help: My regex pattern will match invalid strings

Hello! i really like Regex, unfortantly Im not that good at it yet. So therfore I hope you guys can help me out. The text string I want to validate consists of what I call "segments". A single segment might look like this: [A-Z,S,3] So far I managed to build this regex pattern (?:\[(?<segment>[^,\]\[}' ]+?,[S|D],\d{1})\])+? it w...

Match words separated by punctuation characters using regex

The sample string: this!is.an?example I want to match: this is an example. I tried this: <script type="text/javascript"> var string="this!is.an?example"; var pattern=/^\W/g; alert(string.match(pattern)); </script> ...

Repeating regex groups

I'm trying to get some information from a web site. The information I want is in a table so I made a regex but I don't know the right way to simplify it. The following are two parts of my regex that I would like to simplify: <br>(.*)<br>(.*)<br>(.*) <tr><td>(.+)r>(.+)r>(.+)r>(.+).+</td></tr> # This part should be repeated n times(n = ...

Regular expression for finding class names in HTML

I'd like to use grep to find out if/where an html class is used across a bunch of files. The regex pattern should find not only <p class="foo"> but also <p class="foo bar foo-bar">. So far I'm able to find class="foo" with this example below, can't make it work with multiple classnames: grep -Ern "class=\"result+(\"| )" * Any sugges...

Matching usernames in a memberlist using regex

On a phpBB forum, memberlist.php lists all the members of the board with the following HTML: <a href="profile.php?mode=viewprofile&amp;u=4">Username</a> Where u=4 is the UserID of the user, and Username is obviously their username. There are probably 50-100 peices of HTML like this and I would like to match them all, so I was going t...

Regex to find trailing numbers

I have a string that looks like: www.blah.com/asdf/asdf/asdfasedf/123 The string may have a slash followed by numbers, like /123 in the above example. I want to extract the 123 from the string if it is present. What would my regex be? ...

filter out trailing slash and number

so my urls will look like: /hello-world/blah/ /hello-world/blah /hello-world/blah/234 /hello-world/234 IF the url has a trailing slash followed by numbers, I need to return the same string but with the slash and numbers removed. so the last 2 lines should now look like: /hello-world/blah /hello-world How can I get everything BUT t...

Regex to match html attributes

Hello all, I am trying to match a pattern so that I can retrieve a string from a website. Here is the string in Question: <a title="Posts by ivek dhwWaVa" href="http://www.example.com/author/ivek/" rel="nofollow">ivek</a> I am trying to match the string "ivek" in between the a tag and I want to do this for each post and relate it to ...

How to write MySQL REGEXP?

A table contains the string "Hello world!" Thinking of * as the ordinary wildcard character, how can I write a REGEXP that will evalute to true for 'W*rld!' but false for 'H*rld!' since H is part of another word. 'W*rld' should evalute to false as well because of the trailing '!' ...

Using regex to match string between two strings

How can I use a regular expression to match text that is between two strings, where those two strings are themselves enclosed two other strings, with any amount of text between the inner and outer enclosing strings? For example, I have this text: outer-start some text inner-start text-that-i-want inner-end some more text outer-end ...

Regex Query Builder

Hi, I am a C# developer, I have been looking at regular expressions (regex) and wanted to know if anyone knows about useful tools for building regular expressions - like a regex query builder? ...

Extract text and links from HTML using Regular Expressions

I would like to extract text from an html document keeping the links inside it. for example: From this HTML code <div class="CssClass21">bla1 bla1 bla1 <a href="http://www.ibrii.com"&gt;go to ibrii</a> bla2 bla2 bla2 <img src="http://www.contoso.com/hello.jpg"&gt; <span class="cssClass34">hello hello</span> I would like to extract ju...

How to use str_replace with array or shorten the regex and php instead of repeating three times?

I have the following which replace all of å, ø, æ .... etc to just _. $string = strtolower($string); $regexp = '/( |å|ø|æ|Å|Ø|Æ|Ã¥|ø|æ|Ã…|Ø|Æ)/iU'; $replace_char = '_'; $data = preg_replace($regexp, $replace_char, $string); Now I want to change them to according to the followings. Replace, space to _ å, Å, Ã¥ and Ã… to a, ø,...