regex

Can you help with regular expressions in Java?

I have a bunch of strings which may of may not have random symbols and numbers in them. Some examples are: contains(reserved[j])){ close(); i++){ letters[20]=word I want to find any character that is NOT a letter, and replace it with a white space, so the above examples look like: contains reserved j close i letters word Wha...

replace a pattern

I am using C#3.0 and dotnet framework 3.5. Thanks ...

Regular Expression to recognise truncated forms of search string?

I'm trying to formulate a regular expression which will recognise the search term truncated by any number of characters from the right. For example, if the search term is "pickle", the regex should recognise "pi", "pick" but not "pickaxe". Initially I came up with the following: p(i(c(k(l(e)?)?)?)?)? That works perfectly, but seems ...

How to find if string contains letters and spaces (php)?

So I need to get value false or true if string contains not only letters of all european and east alphabets and " "(space) and "-" minus. How to do such thing with some $a string? ...

Reading a line backwards

Hi, I'm using regular expression to count the total spaces in a line (first occurrence). match(/^\s*/)[0].length; However this reads it from the start to end, How can I read it from end to start. Thanks ...

How to use regular expression in lxml xpath?

I'm using construction like this: doc = parse(url).getroot() links = doc.xpath("//a[text()='some text']") But I need to select all links which have text beginning with "some text", so I'm wondering is there any way to use regexp here? Didn't find anything in lxml documentation ...

Regular expression replace in PL/pgSQL

If I have the following input (excluding quotes): "The ancestral territorial imperatives of the trumpeter swan" How can I collapse all multiple spaces to a single space so that the input is transformed to: "The ancestral territorial imperatives of the trumpeter swan" This is going to be used in a trigger function on insert/...

Very Simple Regex Problem

Hello I want a regular expression which will ignore the sentence containing "XYZ" character. I am using this but this is not working "(.+[^XYZ])" Thanks in advance ...

php regex filename

Hi, anyone can help me with a preg_match? I'd like to use php's preg_match to determine if an input is a valid filename or not (only the filename + file extension, not the full path). General rules: 1) filename = a-z, A-Z, 0-9 2) extension = 3 or 4 letters Thank you! ...

How to match exact string in a webpage in PHP?

We can easily check for a match in a string if (preg_match("/happy/i", "happy is he who has ")) { echo "match found."; } else { echo "match not found."; } ?> But how to check for the occurrence of match in a webpage or given a url? EDIT: How to use Regex to find if a specific string exists within a webpage? I am able to...

Java Regex for matching hexadecimal numbers in a file

So I'm reading in a file (like java program < trace.dat) which looks something like this: 58 68 58 68 40 c 40 48 FA If I'm lucky but more often it has several whitespace characters before and after each line. These are hexadecimal addresses that I'm parsing and I basically need to make sure that I can get the line using a scanner, bu...

Linux distro name parsing

Hello, I chose this way to get linux distro name: ls /etc/*release And now I have to parse it for name: /etc/<name>-release def checkDistro(): p = Popen('ls /etc/*release' , shell = True, stdout = PIPE) distroRelease = p.stdout.read() distroName = re.search( ur"\/etc\/(.*)\-release", distroRelease).group() print dis...

Regular Expression doesn't match

Hi All, I've got a string with very unclean HTML. Before I parse it, I want to convert this: <TABLE><TR><TD width="33%" nowrap=1><font size="1" face="Arial"> NE </font> </TD> <TD width="33%" nowrap=1><font size="1" face="Arial"> DEK </font> </TD> <TD width="33%" nowrap=1><font size="1" face="Arial"> 143 </font> </TD> </TR></TABLE> in...

Help understanding a regular expression

I am an amateur in JavaScript. I saw this other question, and it made me wonder. Can you tell me what does the below regular expression exactly mean? split(/\|(?=\w=>)/) Does it split the string with "|"? ...

Need java regex to match substring with multiple whitespace, only one punctuation.

I want to make sure that the substring I am matching only has one possible piece of punctuation and as much whitespace as necessary. This is inside of a much longer REGEX, currently what there is is the following: [\p{P},\s] but that will match all punctuation and whitespace, so that it accepts: the string before,,,, ,,,. ....the str...

[Qt] Check octal number

Hello, I write simple application in C++/Qt. And i have a text and some octal number in it. My app splits this text by spaces. And i need to check octal numbers from text. How can i select octal numbers from this text with regular expressions? Thank you. ...

Using Regular Expressions

I am having problems trying to use the regular expression that I used in JavaScript. On a web page, you may have: <b>Renewal Date:</b> 03 May 2010</td> I just want to be able to pull out the 03 May 2010, remembering that a webpage has more than just the above content. The way I currently perform this using JavaScript is: DateStr = /...

Regular expression that finds and replaces non-ascii characters with Python

I need to change some characters that are not ASCII to '_'. For example, Tannh‰user -> Tannh_user If I use regular expression with Python, how can I do this? Is there better way to do this not using RE? ...

implementing SRX Segmentation Rules in JavaScript

Hello , I want to implement the SRX Segmentation Rules using javascript to extract sentences from text. In order to do this correctly I will have to follow the SRX rules. eg. http://www.lisa.org/fileadmin/standards/srx20.html#refTR29 now there are two types of regular expressions if found sentence should break like ". " if found se...

Need Help With Simple Regex

I have strings of this type: text (more text) What I would like to do is to have a regular expression that extracts the "more text" segment of the string, so far I have been using this regular expression: "^.*\\((.*)\\)$" Which although it works on many cases, it seems to fail if I have something of the sort: text (more text (even...