regex

C# Regex help - retrieving a number from a sentence

So I have some text that I need to get an integer out of. Here's some examples of what the text could look like: as low as $99 you can get it for $99 or less I need to get the number out of the text, either with or without the $ sign. Can I do this using Regex.Replace? ...

preg_replace: how do I strip off all white space and  ?

Hi, how do I strip off all white space and  ? I have this as a input in a wrapper I create, [b]       bold       [/b] so before turning the text to bold, i want to strip off all white spaces and &nbsp, and turn it into [b]bold[/b], $this->content = preg_replace("/\[(.*?)\]\s\s+(.*?)\s\s+\[\/(.*?)\]...

regex for admitting blank spaces between words in a name in jquery validate

I'm using the following rule in jquery validate to make a name field, called nombre, only accept letters. jQuery.validator.addMethod("nombre", function(value, element, param) { return jQuery.trim(value).match(new RegExp("^(?:" + param + ")$")); }); $("#nombre").rules("add", { nombre: "[a-zA-Z]+"}) I want the regex to ac...

What's the difference between () and [] in regular expression patterns?

What is the difference between encasing part of a regular expression in () (parentheses) and doing it in [] (square brackets)? How does this: [a-z0-9] differ from this: (a-z0-9) ? ...

What is the C# Regex equivalent to Java's appendReplacement and appendTail

UPDATE Here is what I came up with. I haven't tested it yet because it is part of a much larger piece of code that still needs to be ported. Can you see anything that looks out of place? private const string tempUserBlock = "%%%COMPRESS~USER{0}~{1}%%%"; string html = "some html"; int p = 0; var userBlock = new ArrayList(); MatchColle...

C# Regex.Matches returns too many matches?

Hello Can someone explain to me why the result from the following statement has a count of two an not just one? MatchCollection matches = new Regex( ".*" ).Matches( "foo" ) ; Assert.AreEqual( 1, matches.Count ) ; // will fail! new Regex( ".+" ).Matches( "foo" ) ; // returns one match (as expected) new Regex( ".*" ).Matches( "" ) ; // ...

bash script regex to get directory path up nth levels

I'm using PWD to get the present working directory. Is there a SED or regex that I can use to, say, get the full path two parents up? ...

Splitting a string in Java

When I split the string "1|2|3|4" using the String.split("|") I get 8 elements in the array instead of 4. If I use "\\|" the result is proper. I am guessing this has something todo with regular expressions. Can anybody explain this? ...

Regular expression to remove HTML tags

I am using the following Regular Expresion to remove html tags from a string. It works except I leave the closing tag. If I attempt to remove: <a href="blah">blah</a> it leaves the <a/>. I do not know Regular Expression syntax at all and fumbled through this. Can someone with RegEx knowledge please provide me with a pattern that will...

Notepad++ I'm looking for a regexp to select all occurances of 'href="' that do not match 'href="javascript'

This is about the code editor Notepad++. I'm looking for a regular expression that will solve the following problem: I have a set of html files. I need to find all links in them that are not links to javascript functions. If I search for the string 'href="' I get 342 results and if I search for 'href="javascript' I get 301 results. I'd...

Notepad++ Regular Expressions

I'm trying to match <!-- Start Comment content spanning several lines here End Comment --> And I figured something like this would do the trick: (<!-- Start Comment).*(End Comment -->) but the . is not matching newlines. How do I get it to recognize my entire block which contains a host of different characters including newline...

Treat a whole "word" literally in a MySQL regular expression?

I want to do a REGEXP match with MySQL against a variable, like so: SELECT * FROM table WHERE table.CONTENT REGEXP CONCAT('([[:space:]]|[[:punct:]])', table.NAME, '([[:space:]]|[[:punct:]])') This works fine, but it's possible for table.NAME to have regexp special characters in it (e.g. '|'), in which case it gets all screwed u...

How do I extract links from HTML with a Perl regex?

I have a HUGE html which has many things I don't need, but inside it has URLs that are provided in the following format: <a href="http://www.retailmenot.com/" class=l I'm trying to extract the URLs... I tried, to no avail: open(FILE,"<","HTML.htm") or die "$!"; my @str = <FILE>; my @matches = grep { m/a href="(.+?") class=l/ } @str ...

Why is this simple javascript not working?

New to js here. Basically I am trying to detect the existence of a string in the present page's url with this: var url = window.location; var param = /\?provider=/i; if (url.search(param) != -1) { alert('it does exist'); } else alert('it does not exist'); It works when I manually define the url variable like so var url = 'htt...

Php Regex: How to make a submatch optional if is at the end of subject

$text = 'something here *ls67 another thing'; // match $text2 = 'something here *ls67. another thing'; // match $text3 = 'something here another thing *ls67.'; // match $text3 = 'something here another thing *ls67'; // doesn't match (and i need to match this) $pattern = '|^(.*)?(\*[0-9a-zA-Z_-]{3,15})([^0-9a-zA-Z_-])+(.*)?$|i'; I've...

ASP.net: How to get the content of a specific html element on server side

I get some URL from a XML feed. Now the question is how do I get a specific data from each page represented by those URLs. For example if I have a URL: www.abc.com in the feed data and on that page there is a table like this: <table> <body> <tr> <td class="snip"> <span class="summary"> abc ... abc &amp; xyz ... <br> ..........

Excluding strings using regex

I was working on creating a regex which will include all patterns except 'time', 'hour', 'minute' so, worked this out: ^(?:(?!time).)*$ how do i add for the other 2 words also? I tried as follows but it is incorrect. ^(?:(?![time][hour][minute]).)*$ Is there a better way to do this? I am not adding the values which can be accepted...

Javascript REGEX: How to get `1` and not `11`

If I do this: var string = "7,11,2" var check = string.match("/1/"); if(check != null){ doSomething(); } else { doSomethingElse(); } Then check is not null because match has found 1 in 11. So how should I avoid this and get 1 when it really appears? ...

What's the problem with my script?

Why is this giving me null? <script language="javascript"> var element = "11"; var string = "7,11"; var check = string.match("/(^|\D)"+element+"(\D|$)/g"); alert(check); </script> When I run the regex on http://regex.larsolavtorvik.com/ it works correctly. Pleeeease help I want to sleeeep! :)) ...

jQuery: How can I match text with a RegEx pattern and wrap the results in an anchor tag?

I have a bunch of tweets that are returned as plain text that I would like to go through and assign proper links tags to based on RegEx matches. As an example here is a tweet where I would like @Bundlehunt to become <a href="http://twitter.com/bundlehunt"&gt;@Bundlehunt&lt;/a&gt; and the http://bundlehunt.com should become <a href="http...