regex

Regexp - search for text which doesn't contain whole word

I have text similar like this: <html><p>this is <b>the</b> text</p> and <p>this is another text</p></html> and I need to get this text using regexp this is <b>the</b> text Problem is, when I use simple regexp like this (<html>.*</p>) I'm getting whole text until the last occurence of </p> Can anyone help me? thanks lennyd ...

Regex - repeating matches

Another regexp question I have input text like this: test start first end start second end start third end and I need matches like this: test first test second test third I've tried something like that: start(.*?)end but how to add "test"? Thanks for any suggestion Lennyd (edited - there was mistake in input text) There ...

What is the easiest way in C# to validate if a regular expression is well formed?

Is there any simple way in C# to test if a regular expression is a regular expression? In other words, I would like to check if a user-provided regex pattern is malformed or not. This is purely a syntax test and not what the regex is supposed to achieve/test. Thanks ...

Javascript String Replace

I have a string of tags delimited by semicolons: "red; yellow; blue; green; purple" I would like to strip out all the tags that do not match a substring (case-insensitive.) For example, if I have a substring "Bl" I would like to return "blue". Any suggestions as how to best accomplish this in javascript? Specifically, I'm wonderi...

Extracting portions of a loaded page in PHP (RegEx)

I have a newsletter system I am trying to incorporate within a PHP site. The PHP site loads a content area and also loads scripts into the head of the page. This works fine for the code that is generated for the site but now I have the newsletter I am trying to incorporate. Originally I was going to use an iFrame but the amount of AJAX ...

Ruby: What's the proper syntax for a boolean regex method?

What is the proper syntax for a method that checks a string for a pattern, and returns true or false if the regex matches? Basic idea: def has_regex?(string) pattern = /something/i return string =~ pattern end Use case: if has_regex?("something") # woohoo else # nothing found: panic! end ...

PHP: Simple regular expressions to match length?

I'm creating a registration system that needs to check the name/pass etc. with REGEX (and prefer to), what I've got so far is: //Check so numbers aren't first, such as 00foobar preg_match('/^(?!\d)[a-z0-9]+$/iD',$usrname); //Just simple check preg_match('/^[a-zA-Z0-9]+$/',$psword); But I have to do stupid things in IF statements like:...

Match URL link from input string

How do I match the URL address in this string, I have other code that matches text and it seems to work, but when I try to use it here, it doesn't, it keeps saying there is "No such file or directory. I didn't know grep -o only worked on files? matchString='url={"urlPath":"http://www.google.com/","thisIsOtherText"' array=($(grep -o 'url...

PHP: Inject iframe right after body tag

I would like to place an iframe right below the start of the body tag. This has some issues since the body tag can have various attributes and odd whitespace. My guess is this will will require regular expressions to do correctly. EDIT: This solution has to work with php 4 & performance is a concern of mine. It's for this http://drupal....

PHP: How do I convert a regular expression to an example match?

Hi, I have a regular expression for matching URIs: eg: preg_match("/^my\/uri\//i", "my/uri/whatever"); which I use for routing: eg: "http://www.mywebsite.com/my/uri/page.html" will match the above (with the protocol/host removed of course) now I was wondering if there was any way to evaluate the regular expression into the most gener...

How to add attribute to first P tag using PHP regular expression?

WordPress spits posts in this format: <h2>Some header</h> <p>First paragraph of the post</p> <p>Second paragraph of the post</p> etc. To get my cool styling on the first paragraph (it's one of those things that looks good only sparingly) I need to hook into the get_posts function to filter its output with a preg_replace. The goal is ...

PHP: How do I strip all regex?

How do strip all regex special characters from a string? eg: I have "/^bla\/bla\/bla\//i" which I want to be: "bla/bla/bla/" ...

SQL query with regex in ms-access database

Hi, I'm working with C# .Net and ms-access database. I have the following SQL query: `Select ... Like "%<aaa>%"+prmPhrase+"%</aaa>%"` The query is looking for a phrase inside a database field which contains xml data. the query works very quickly, but it returns a lot of false results. I can't search only the exact phrase becau...

How to evaluate a matched number later in a regex? - Lexing FORTRAN 'H' edit descriptor with Ply

I am using Ply to interpret a FORTRAN format string. I am having trouble writing a regex to match the 'H' edit descriptor which is of the form xHccccc ... where x specifies the number of characters to read in after the 'H' Ply matches tokens with a single regular expression, but I am having trouble using regular expression to perform ...

Fix JQuery-1.4.1 and json-2.0 conflict in json.parse regex conflict with "$" character

After upgrading to jquery 1.4.1 i noticed there was an error anytime i tried calling json.parse. The issue is part of the regex used in json. it uses a $ in the pattern that conflicts with JQuery's $ shortcut. I don't want to use the non-conflict option with jquery because i have tons of places i'd have to replace the $ with the new cor...

Help me with Regular expression

I want to cut only ALLS WELL THAT ENDS WELL until Florentine. That mean cut all license off. How to I write the expression ? <<THIS ELECTRONIC VERSION OF THE COMPLETE WORKS OF WILLIAM SHAKESPEARE IS COPYRIGHT 1990-1993 BY WORLD LIBRARY, INC., AND IS PROVIDED BY PROJECT GUTENBERG ETEXT OF ILLINOIS BENEDICTINE COLLEGE WITH PERMISSION. E...

Problem with getting to the second rewrite rule: is the first too general?

Hi, as i describe already above if i call e.g. /berlin it properly routes, but if i try /berlin-blabla-50-prozent-rabatt.html it also takes the first rule,i'm not sure how to negate the regex telling if it has "-" or something like that take the second. I also got a problem, if i put a trailing / it also breaks, do i have to add a third ...

regular expression for option-style string

Hi, another one stuck in Regex land... having the following line Word "Blabla" -Option1:Bla di Bla -Option2:Ha I want to match the 2 "options" at the end such that I have the groups: Option1 Bla di Bla Option2 Ha What I have so far is this: -(\w+?):(.+?)(?=-|$) Which I thought should mean: "A hyphen, followed by a word, followe...

RegEx Removing Methods from Code

With Regular Expressions I'm trying to remove all the methods/functions from the following code. Leaving the "global scope" alone. However, I can't manage to make it match for all the inner content of a method. <?php $mother = new Mother(); class Hello { public function FunctionName($value="username",) { } public functi...

How to replace ereg?

Hi all, I'm getting the following message for some php I have to use but did not write: Deprecated: Function ereg() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/html2fpdf.php on line 466 This is line 466: if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3)) I tried simply replacing with preg_match, but it couldn't re...