regex

regex help, find first 3 occurrences of a keyword and str_ireplace the content

Given a block of text, I need to parse it for the existing of a keyword. Then on the first appearance of the keyword, I need to wrap bold tags around it (if it doesn't already have them), on the second appearance of the keyword, italics, and on the third, underline. Example using the keyword "help": This is some text with the keyword "...

Replacing two regexes in one pass

I want to make two regex replacements on one string, i.e. in Java terms myString.replaceAll(pattern1, replacement1).replaceAll(pattern2, replacement2); However, suppose that myString may be very long, so it would be desirable to avoid doing two passes over it. Can this be done in single pass? String pattern = ...; String replacement...

HtmlAgilityPack: Convert parsed Javascript string to JSON

Hello! So, I am using the HtmlAgility pack (http://htmlagilitypack.codeplex.com/) to parse a script node and then I use regular expressions to parse out an object definition. The string I end up with is plain javascript that defines an object. Here is the sample Javascript I am trying to parse: <!--Module 328 Buying Options Table--> <...

parse content for appearance of a keyword inside h1, h2 and h3 heading tags

Given a block of content, I'm looking to create a function in PHP to check for the existence of a keyword or keyword phrase inside an h1-h3 header tags... For example, if the keyword was "Blue Violin" and the block of text was... You don't see many blue violins. Most violins have a natural finish. <h1>If you see a blue violin, its real...

C# and JavaScript results from same regular expression string are very different - how can I make results more consistent?

The reg ex string is as follows: px\">(.+)</SPAN When I use this code with this expression in C#, and compare with the body of an html document, I get back a short string like so: Match match = Regex.Match( fullText, regExString, RegexOptions.IgnoreCase ); .. gets px">Cart is empty </span><a href="http://www.somesite.co.uk/shop/ca...

Evaluate keyword density of a given block of text

I would like to use php to pass a keyword phrase to a function and have the function parse a block of text and return the keyword density of the input phrase as a percentage of the total word count of the text block. ...

PHP :: handle typos in search

I have a field to input your friend's name and search him up to add him as friend. The problem is that if you are not sure how to spell his name like: Kris instead of Chris for example. I think the right way to do this is use RegEx but I don't know how... How can I handle those kind of typos in PHP ? (if it isn't possible in PHP then...

splitting a string in js where a pattern DOES NOT match?

i am trying to split a TextArea value where a pattern does not match the text is like following: Some Good Tutorials http://a.com/page1 http://a.com/page2 Some Good Images http://i.com/p1 http://i.com/p2 Some Good Videos http://m.com/p1 http://m.com/p2 now i want to get only the links from the text so a better solution would be to sp...

RegexpError: Stack overflow in regexp matcher

I have small problem with a simple tokenizer regex: def test_tokenizer_regex_limit string = '<p>a</p>' * 400 tokens = string.scan(/(<\s*tag:.*?\/?>)|((?:[^<]|\<(?!\s*tag:.*?\/?>))+)/) end Basically it runs through the text and gets pairs of [ matched_tag , other_text ]. Here's an example: http://rubular.com/r/f88JBjfzFh Works f...

How to make a "minimal match" Regex search in C#?

Let's say I have a multi-line string like this: STARTFRUIT banana ENDFRUIT STARTFRUIT avocado ENDFRUIT STARTVEGGIE rhubarb ENDVEGGIE STARTFRUIT lime ENDFRUIT I want to search for all fruit, no veggies. I try this: MatchCollection myMatches = Regex.Matches(tbBlob.Text, "STARTFRUIT.*ENDFRUIT", RegexOptions.Singleline); foreach (var...

mod_rewrite with multiple embedded matches

I have the following rewrite rule in my .htaccess file: RewriteRule ^([^/]+)/([^/]+)/(tab:([^/]+)/?)?(scope:([^/]+)/?)?(sort:([^/]+)/?)?(p:\d+)/?)?$ web/results.php?view=$1&q=$2&tab=$4&searchscope=$6&sortBy=$8&page=$10 [NC,QSA,L] It seems to work great when testing on some of the online regex testers that I have found. However on this ...

How can I parse <img src> with a regex?

I need a clever regex to match ... in these: <img src="..." <img src='...' <img src=... I want to match the inner content of src, but only if it is surrounded by ", ' or none. This means that <img src=..." or <img src='... must not be accepted. Any ideas how to match these 3 cases with one regex. So far I use something like this ("|...

RegEx a substring in a specific combo

Say i have a string as follows ' *my test string 1 111:222:444: &EVERYTHING INSIDE THIS REGARLESS OF CHAR OR INT£ This is a test string (123456789)' I want to return every thing inside & and the £ sign or match it. Any body could help me with the regex expression for this. ...

VBScript - Regular Expression replace spaces

I have a situation where using VBScript I need to check for the presence of multiple spaces. I want to check for the presence of 2 or more consecutive spaces, so \s+ doesnt work for my needs. Does anyone know how I can accomplish this using VBScript regular expressions. ...

Regex expression for "string x/0/y"

Hallo everyone, I am trying to find a resolution for a regex expression: I want to have something like this "string x/0/y" where x is in a range between 1-6 and y is in range between 1-48 I tried this: interface GigabitEthernet [1-6]/0/([1-4]*[1-8]) but then if y = 50 it still takes 5 under consideration and drops "0" I tried th...

Regular expression to match all content between 2 tags

Hello, I am trying to capture the following content in PHP using regular expressions: /* Name: Test Description: my test */ I have tried the code from here: http://stackoverflow.com/questions/287991/match-everything-inbetween-two-tags-with-regular-expressions but it doesnt capture the new lines. EDIT: I used the ...

Text editor that searches within search results

Does anyone know of a text editor that searches within search results using regex? I would like to perform a regex search on several text files and get a list of matches and then apply another regex search on the search results to further narrow down results. I would prefer a Windows GUI editor rather than a specialized editor with a st...

Differences in regex syntax in Python and Java

Hi, I have a following working regex in Python and I am trying to convert it to Java, I thought that regex works the same in both languages, but obviously it doesn't. Python regex: ^\d+;\d+-\d+ My Java attempt: ^\\d+;\\d+-\\d+ Example strings that should be matched: 3;1-2,2-3 68;12-15,1-16,66-1,1-2 What is the right solution in Ja...

Can someone define the regular expression to match the following html code

I was doing some web scraping and i was looking for some div elements with particular class names and markup. This is my objective , i have to extract everything within the div having the class s_specs_box s_box_4 Could someone please provide the regular expression in .NET terms (i.e., which can be straight away passed into Regex's con...

Manipulating preg_replaces's 'replace' value

I'm trying to alter the match value from preg_replace with an uppcase copy but cant seem to figure it out... I've tried: preg_replace("#\[name=((?:keywords)|(?:description))\]#is", "[name=" . strtoupper($1) . "]" ,$str ) and preg_replace("#\[name=((?:keywords)|(?:description))\]#is", "[name={strtoupper($1)}]" ,$str ) but none work...