regex

Java: calculate linenumber from charwise position according to the number of "\n"

I know charwise positions of matches like 1 3 7 8. I need to know their corresponding line number. Example: file.txt Match: X Mathes: 1 3 7 8. Want: 1 2 4 4 $ cat file.txt X2 X 4 56XX [Added: does not notice many linewise matches, there is probably easier way to do it with stacks] $ java testt 1 2 4 $ cat testt.java imp...

Regular expression for required format

What will be the best regular expression if I want to intake alphanumerics, '-' and '+' signs. e.g. LA2+4 or td1-23 ...

Poorly performing regex

I've a really poorly performing piece of regex, currently it makes Firefox, Chrome and IE hang for a period of time. Here's the reg-ex: ^([a-zA-Z0-9]+[/]?)+[a-zA-Z0-9]+$ It's kind of a url matcher, but should only match the requested path (not starting with or ending with a slash). Valid examples: Segment Segment/Segment segment/...

Invalid XML Replace Content in PHP

I have a invalid XML like this Warning: count() [function.count]: Node no longer exists in /var/bla/test.php <?xml version="1.0" encoding="ISO-8859-1"?> <nodes> <some>test</some> </nodes> Now i need a regex which would replace the Warning: count() [function.count]: Node no longer exists in /var/bla/test.php with "" how can i do that? ...

Regex match numerical range

I am trying to write a simple regex to match a percentage value range 1%-100% Is there a better way to write this? ^([1-9]|[1-9][0-9]|100)%$ ...

Regular expression to extract text between two sets of characters (Javascript)

I would like to extract some text between two points in a string, in Javascript Say the string is "start-extractThis-234" The numbers at the end can be any number, but the hyphens are always present. Ideally I think capturing between the two hypens should be ok. I would like the result of the regex to be extractThis ...

Regex Query to get string value

Hi all, I am looking for a regex query that would allow me to retrieve a value from a string here are examples of my string: home.aspx?StudyID=0020101&aa=72 randompage.aspx?studyid=3023603&aa=40 myconfig.aspx?studyid=0021600&aa=40 I need to get the numerical value of the 'studyid' variable, please note that the name of the page will c...

Notepad++ regex to find 3 consecutive numbers

I'm trying to use Notepadd++ to find all occurrences of width=xxx so I can change them to width="xxx" as far as I have got is width=[^\n] which only selects width=x ...

not autolinking all-numeric twitter hashtags in perl?

I'm producing HTML from twitter search results. Happily using the Net::Twitter module :-) One of the rules in Twitter is that all-numeric hashtags are not links. This allows to unambiguously tweet things like "ur not my #1 anymore", as in here: http://twitter.com/natarias2007/status/11246320622 The solution I came up with looks like: ...

how to check if file is php?

i want to check if a file has the extensions .php. if it has i include it. could someone help me with a regexp check? thanks! ...

Lua pattern matching vs. regular expressions

Hello, I'm currently learning lua. regarding pattern-matching in lua I found the following sentence in the lua documentation on lua.org: Nevertheless, pattern matching in Lua is a powerful tool and includes some features that are difficult to match with standard POSIX implementations. As I'm familiar with posix regular expressions...

Extract parts of html using regex

I have a simple requirement to extract text in html. Suppose the html is <h1>hello</h1> ... <img moduleType="calendar" /> ...<h2>bye</h2> I want to convert it into three parts <h1>hello</h1> <img moduleType="calendar" /> <h2>bye</h2> The aim is to extract text in two categories, simple html and special tags with <img mo...

Parsing a list of values of the form `{value}` with regular expressions

I have one string like the following (the number of the {} is unknown): {test}{test1}{test2}{test3}{test4} Now I like to get the content in {} out and put them into array. How can I do this? I tried: preg_match( "/(\{{\S}+\}*/)*") But the result is wrong. Thanks so much for anyone's help. ...

Regex: Getting content from URL

I want to get "the-game" using regex from URLs like http://www.somesite.com.domain.webdev.domain.com/en/the-game/another-one/another-one/another-one/ http://www.somesite.com.domain.webdev.domain.com/en/the-game/another-one/another-one/ http://www.somesite.com.domain.webdev.domain.com/en/the-game/another-one/ ...

Oracle - Determine maximum supported size for regular expression

I have a regular expression that throws ORA-12733, "regular expression is too long". How do I determine what the maximum supported size is? FYI: the offending regex is 892 characters. It's a generated regex, so I could change how I generate and execute it, but I would like to know what the limits to the max size are before I change how ...

return empty string from preg_split

Right now i'm trying to get this: Array ( [0] => hello [1] => [2] => goodbye ) Where index 1 is the empty string. $toBeSplit= 'hello,,goodbye'; $textSplitted = preg_split('/[,]+/', $toBeSplit, -1); $textSplitted looks like this: Array ( [0] => hello [1] => goodbye ) I'm using PHP 5.3.2 ...

Regex: Skip/Ignore pattern

Given that the following string is embedded in text, how can I extract the whole line but not matching on the inner "<" and ">"? <test type="yippie<innertext>" /> EDIT: Being more specific, we need to handle both use cases below where "type" has or does not have "<" and ">" chars. <h:test type="yippie<innertext>" /> <h:test type="yip...

ruby-regex: how to match for "/table[number]" ?

i want to match for all "/table[number]" so strings like "/table[1]" and "/table" are matched. ...

Problems with matching emails with regex

Hello, I'm trying to match an email address here is what I've come up with so far : String text = "[email protected]"; String regex = "(\\w+)@{1}(\\w+){2,}\\.{1}\\w{2,4}"; This however works with following cases : [email protected] [email protected] [email protected] So it matches any alphanumeri...

[Python] OR in regular expression?

Hello. I have text file with several thousands lines. I want to parse this file into database and decided to write a regexp. Here's part of file: blablabla checked=12 unchecked=1 blablabla unchecked=13 blablabla checked=14 As a result, I would like to get something like (12,1) (0,13) (14,0) Is it possible? ...