regex

Regular expression either/or not matching everything

I'm trying to parse an HTTP GET request to determine if the url contains any of a number of file types. If it does, I want to capture the entire request. There is something I don't understand about ORing. The following regular expression only captures part of it, and only if .flv is the first int the list of ORd values. (I've obscu...

Strange, regex.split Method matches one null element

Regex rx = new Regex(@"[+-]"); string[] substrings = rx.Split(expression); expression = "-9a3dcbh-3bca-4ab4cf-3hc" //This is the iput string I want to split that string between + or -. My VS debugger shows substring array like this: substrings[0] = null //???Why substrings[1] = 9a3dcbh substrings[2] = 3bca substrings[3] = 4ab4...

How to extract product weight from this HTML

My HTML looks like this: <td class="main"><b>Product Weight (2.83 lbs in 1 container)</b></td> I need to get the value 2.83 from the HTML. Need help with the regex. I have this: Pattern p = Pattern.compile( "<td\\sclass=\"main\"><b>Product\\sWeight\\s\\s((?:\\d+\\.)?\\d+ \\w{3})"); But doesn't seem to be working. Am I mi...

How to use variables with regex?

This is the input string: 23x^45*y or 2x^2 or y^4*x^3. I am matching ^[0-9]+ after letter x. In other words I am matching x followed by ^ followed by numbers. Problem is that I don't know that I am matching x, it could be any letter that I stored as variable in my char array. For example: foreach (char cEle in myarray) // cEle is lett...

Java RegEx Pattern not matching (works in .NET)

Below is an example that is producing an exception in Java (and not matching the input). Perhaps I misunderstood the JavaDoc, but it looks like it should work. Using the same pattern and input in C# will produce a match. import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(Str...

Regex file extension filter

I am trying to create a regex that will take all files that do not have a list of extensions. In particular, I am trying to filter out filenames that end in .csv I have browsed around for an hour and been unable to figure this out. I am using .NET Regex. ...

Remove duplicate characters using a regular expression

I need to Match the second and subsequent occurances of the * character using a regular expression. I'm actually using the Replace method to remove them so here's some examples of before and after: test* -> test* (no change) *test* -> *test test** *e -> test* e Is it possible to do this with a regular expression? Thanks ...

negative look ahead to exclude html tags

I'm trying to come up with a validation expression to prevent users from entering html or javascript tags into a comment box on a web page. The following works fine for a single line of text: ^(?!.*(<|>)).*$ ..but it won't allow any newline characters because of the dot(.). If I go with something like this: ^(?!.*(<|>))(.|\s)*$ i...

Need variable width negative lookbehind replacement

I have looked at many questions here (and many more websites) and some provided hints but none gave me a definitive answer. I know regular expressions but I am far from being a guru. This particular question deals with regex in PHP. I need to locate words in a text that are not surrounded by a hyperlink of a given class. For example, I ...

Regular expression for strings with an even number of zeroes and ones

What is a regular expression for strings of 0 and 1 with an even number of zeros and an even number of ones? I have something like (1*01*01*)*(0*10*10*)*. Does it look good? ...

Powershell replace lose line breaks

Hi, I am a newbie in powershell. I have a simple powershell script that just replace text but I found that the regex replace turn my multiline data source into a single line text when the output is produced. I want the line breaks to be preserved. Here is the dumb down version of the script. $source=(Get-Content textfile.txt) $process1...

Regex to represent "NOT" in a group

I have this Regex: <(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s([\w\/\.\-]*)(.*) What I want to do is to return FALSE(Not matched) if the third group is "MSWinEventLog" and returning "matched" for the rest. <166>Apr 28 10:46:34 AMC the remaining phrase <11>Apr 28 10:46:34 MSWinEventLog the remaining phrase <170>Apr 28 10:46:34 Avantail the re...

Rails regex to extract Twitpic link/code if present

Provided a url, within a string of text (tweet) such as "Check out my twitpic http://twitpic.com/1876544594 its awesome" I need a Rails regex that will return 18744594, the id of this particular twitpic... This question has been asked here but was for PHP, and I need it for Rails. I would also be able to pull the name of the site, s...

String replacement in PHP

This is my first question on this wonderful website. Lets say I have a string $a="some text..%PROD% more text" There will be just one %..% in the string. I need to replace PROD between the % with another variable content. So I used to do: $a = str_replace('%PROD%',$var,$a); but now the PROD between % started coming in different case...

Php preg_replace pattern help

I have this text: Lorem ipsum dolor sit {something.something({print.print(param1,param2)},param2)}, consectetur adipiscing elit. Where i need a pattern that can replace everything but: something.something The text something.something can contain [a-zA-Z.] (I am using preg_replace) Here is a site where you can test the code:...

document.URL Matching in Javascript

I have a url which looks like this https://test.high.com/people/11111111-name-firstname-_custa/deals/new Now i need to match document.URL if im on that Page if so i will alert a message. The important part is /deals/new How can i match that in Javascript? ...

How do I replace characters not in range [0x5E10, 0x7F35] with '*' in PHP?

I'm not familiar with the how regular expressions treat hexadecimal, anyone knows? ...

Use regex backreference in calculation(Java,Netbeans and not only)

In Netbeans the "Replace command"(ctrl+H) has a regular expression checkbox so that i can search and replace in the document using regex's. Also i can replace using a backreference. The question is can i use a backreference in a calculation and then use it? For example with the use of "([0-9]{1})" in the "Find what" i will find all the...

Split string into smaller part with constrain [PHP RegEx HTML]

Hello, I need to split long string into a array with following constrains: The input will be HTML string, may be full page or partial. Each part (new strings) will have a limited number of character (e.g. not more than 8000 character) Each part can contain multiple sentences (delimited by . [full stop]) but never a partial sentences. ...

PHP preg_match to get function-like string

Hi to all, if I have a string like 'foo(bar)', with the following code i can almost parse it the way i want: $results = array(); preg_match( "/\w*(?=(\(.*\))?)/", 'foo(bar)', &$results ); print_r($results); /* Array ( [0] => foo [1] => (bar) ) */ How can I modify the regex to have bar instead of (bar)? Thanks ...