regex

why making a user registration must be regular?

hello, everyone. I'm programming a user registration. However, I found a charactor limiting to 'username' from sample codes, such as just '.', ''', '-' are accepted, no space or other blank, etc. Are those restrictions necessary? I'm using MySQL+PHP. If I adopt the following several ways: change the collation of the column to '...

Extra backslash needed in PHP regexp pattern

When testing an answer for another user's question I found something I don't understand. The problem was to replace all literal \t \n \r characters from a string with a single space. Now, the first pattern I tried was: /(?:\\[trn])+/ which surprisingly didn't work. I tried the same pattern in Perl and it worked fine. After some trial...

Selecting before after character in regex

Basically I'm trying to get a bit of regex to do the following... I have some data I need to split, the sample data looks like this: Brand Name - Product Name Another Brand - Shoe Laces Heinz - Bakes Beans I want to be able to select the brand name or the product name but I can't seem to do it without catching the " - " part in the re...

How to tell if a html string will show as empty in the browser? (C# / regex?)

Hi, I have a control that will return some html to me as a string. Before putting that on screen, I'd like to be able to tell if it'll just show as empty. For example the control might return <p><br /></p>, which when I test using C# for string.Emtpy obviously it's not - but nothing gets displayed on screen. Is there a regex function ...

SQL Server function to eliminate replicated characters

I wonder if there is an easy and efficient way in SQL Server 2005 to eliminate replicated characters in a string. Like converting 'ABBBCDEEFFFFG' to 'ABCDEFG' It really sucks that SQL Server has such a poor string library and no ready-to-use regexp feature... ...

Can someone please help me understand this Regular Expression?

I have the following regular expression: (?=.{8,})[a-zA-Z]+[^a-zA-Z]+|[^a-zA-Z]+[a-zA-Z]+ I do not understand the "?=" part of it. My basic (incorrect) understanding is that it is saying a string that is 8 characters or more long, which has one or more letters followed by one or more non-letters, or one or more non-letters followe...

Need simple regex for LaTeX

In my LaTeX files, I have literally thousands of occurrences of the following construct: $\displaystyle{...math goes here...}$ I'd like to replace these with \mymath{...math goes here...} Note that the $'s disappear, but the curly braces remain---if not for the trailing $, this would be a basic find-and-replace. If only I knew any...

Combining .net Regular expressions

I am trying to merge two .net regular expressions into one. The following expressions are validating excel like cell names. Regex.IsMatch(name, @"^[A-Za-z]{1}[\w\.]*$") && !Regex.IsMatch(name, @"^[A-Za-z]{1,2}\d+$"); The first part ensures the cell name starts with a character and can be any length. The second ensures the cell na...

Problem with regular expression lookbehinds in javascript

Hi I want to retrieve via regexp javascript figures 1 - preceded by either: And | or nothing 2 - followed by either: Nothing And | or I thought of using lookbehind but it seems that javascript does not support lookbehind thank you for helping me ...

Case sensitive replace for case insensitive search with regex

Ok so I doing the following regex replace: Input: ([Ll])ocation Output: \1abel That replaces Location with Label and location with label. However, if I want to replace location with geocode and Location with Geocode, can I do that with a single regex? I'm doing a search and replace in notepad++ at the moment, but I've had this probl...

Regex Quoted String with Escaped Quotes in C#

I'm trying to find all of the quoted text on a single line. Example: "Some Text", and "Some more Text" and "Even more text about \"this text\"" I need to get: "Some Text" "Some more Text" "Even more text about \"this text\"" \"[^\"\r]*\" gives me everything except for the last one, because of the escaped quotes. I have read abo...

How do I find the shortest overlapping match using regular expressions?

I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example: import re string = "A|B|A|B|C|D|E|F|G" my_pattern = 'a.*?b.*?c' my_regex = re.compile(my_pattern, re.DOTALL|re.IGNORECASE) matc...

Regex: get content between [%= and %]

Hi, Can somebody help me to get a content between [%= and %]. ...

Help with sed regex: extract text from specific tag

First time sed'er, so be gentle. I have the following text file, 'test_file': <Tag1>not </Tag1><Tag2>working</Tag2> I want to extract the text in between <Tag2> using sed regex, there may be other occurrences of <Tag2> and I would like to extract those also. So far I have this sed based regex: cat test_file | grep -i "Tag2"| sed '...

Regex DATE format validation on Java

Hello! I'm just wondering if there is a way (maybe with REGEX) to validate that an input on a java desktop app is exactly an string formated as: "YYYY-MM-DD". I've search but with no success. Thank you ...

Python: How does regex re.compile(r'^[-\w]+$') search? Or, how does regex work in this context?

By reading the documentation here it seems to me that re.compile(r'^[-\w]+$') would just search whether there was any character that is alphanumeric, an underscore, or a hyphen. But really this returns a match only if all the characters fit that description (ie, it fails if there is a space or a dollar sign or asterisk, etc). I don't...

Can somebody explain a money regex that just checks if the value matches some pattern?

There are multiple posts on here that capture value, but I'm just looking to check to see if the value is something. More vaguely put; I'm looking to understand the difference between checking a value, and "capturing" a value. In the current case the value would be the following acceptable money formats: Here is a post that explains som...

Regex: How to match a decimal '.' if it's follow by or preceded by (or both) a '\d' decimal number

Here's what I currently have, but it only works if the decimal is preceded and followed by a decimal. ^\$?(\d*?(?<=\d)\.?(?=\d)\d*?)$ So the string: '$50.00' matches, but '$.50', and '$50.' don't match (I want them to) I want to retrieve the matched decimal like '50.00' in a single group if possible so that I can grab the normalized ...

regular expression requires something in front but does not include that in the match

I want a regex that will generate a match when it encounters "integer xyz" but only returns 'xyz' as the matching text. 'xyz' can be an identifier (letters+digits+underscore). xyz by itself generates no match, only xyz preceded by 'integer ' thanks! ...

regex for at least 2 empty space ?

i need to ignore anything that is one space, and empty space at least bigger than one space should be matched... "MARY HAD A LITTLE LAMB" i expect "MARY", "HAD A LITTLE", "LAMB" ...