regex

Regex Replace to assist Orderby in LINQ

I'm using LINQ to SQL to pull records from a database, sort them by a string field, then perform some other work on them. Unfortunately the Name field that I'm sorting by comes out of the database like this Name ADAPT1 ADAPT10 ADAPT11 ... ADAPT2 ADAPT3 I'd like to sort the Name field in numerical order. Right now I'm using the Regex...

Is there a CheckStyle rule to force if else keywords to be on the same line in an if/else ladder?

Based on this question it appears that the default template for CheckStyle will allow if else ladders to separate the if and else with a line break. Meaning I would like this code to be flagged as a violation: if (true) { System.out.println("20"); } else if (true) { System.out.println("30"); } Is there a Ch...

Chanukah Regex

Hannuka, Chanukah, Hanukkah...Due to transliteration from another language and character set, there are many ways to spell the name of this holiday. How many legitimate spellings can you come up with? Now, write a regular expression that will recognise all of them. ...

Regular expression for allow only numbers

I want to check the following with regular expression {Today,Format} Today - will be remains as it is. In the place of Format, we can allow the digits from 0 to 12. for example: we have to allow {Today,0} {Today,1} {Today,2} ... {Today,12} and also have to allow {Today,} {Today,Format} Please help me and also refer me to some ...

RegEx for Javascript to allow only alphanumeric

I need to find a reg ex that only allows alphanumeric. So far, everyone I try only works if the string is alphanumeric, meaning contains both a letter and a number. I just want one what would allow either and not require both. Thanks! ...

How can I split "lastname, firstname" into separate strings?

Whats the best way to separate the string, "Parisi, Kenneth" into "Kenneth" and "Parisi"? I am still learning how to parse strings with these regular expressions, but not too familiar with how to set vars equal to the matched string & output of the matched (or mismatched) string. ...

Template ifs using regex

Hey everyone, I'm working on a PHP application that needs to parse a .tpl file with HTML in it and I'm making it so that the HTML can have variables and basic if statements in it. An if statement look something like this: ` <!--if({VERSION} == 2)--> Hello World <!--endif --> To parse that, I've tried using preg_replace with no luck. T...

Convert > to HTML entity equivalent within HTML string

I'm trying to convert all instances of the > character to its HTML entity equivalent, >, within a string of HTML that contains HTML tags. The furthest I've been able to get with a solution for this is using a regex. Here's what I have so far: public static readonly Regex HtmlAngleBracketNotPartOfTag = new Regex("(?:<[^>]*(?:>|$...

Regex misspellings

I have a regex created from a list in a database to match names for types of buildings in a game. The problem is typos, sometimes those writing instructions for their team in the game will misspell a building name and obviously the regex will then not pick it up (i.e. spelling "University" and "Unversity"). Are there any suggestions on ...

How to use a variable in the replacement side of the Perl substitution operator?

I would like to do the following: $find="start (.*) end"; $replace="foo \1 bar"; $var = "start middle end"; $var =~ s/$find/$replace/; I would expect $var to contain "foo middle bar", but it does not work. Neither does: $replace='foo \1 bar'; Somehow I am missing something regarding the escaping. I fixed the missing 's' ...

Regular Expression to extract label-value pairs in Java

I have a file containing several lines similar to: Name: Peter Address: St. Serrano número 12, España Country: Spain And I need to extract the address using a regular expression, taking into account that it can contain dots, special characters (ñ, ç), áéíóú... The current code works, but it looks quite ugly:. Pattern p = Pattern.com...

Matching rounds...

Hello. I have some text with the following structure: Round 1 some multiline text ... Round 2 some multiline text ... ... Round N some multiline text ... I'd like to match rounds with their multiline text. None of the expressions produces correct result: (Round\s\d+)((?!Round).*?) (Round\s\d+)(.*?) Could someone help me? T...

python and regular expression with unicode

I need to delete some unicode symbols from the string 'بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ' I know they exist here for sure. I try: re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', 'بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ') but it doesn't work. String stays the same. ant suggestion what i do wrong? ...

Regular Expression to Detect a Specific Query

Hi, I wonder if you anyone can construct a regular expression that can detect if a person searches for something like "site:cnn.com" or "site:www.globe.com.ph/". I've been having the most difficult time figuring it out. Thanks a lot in advance! Edit: Sorry forgot to mention my script is in PHP. ...

Count occurrences of a word in a row in MySQL

I'm making a search function for my website, which finds relevant results from a database. I'm looking for a way to count occurrences of a word, but I need to ensure that there are word boundaries on both sides of the word ( so I don't end up with "triple" when I want "rip"). Does anyone have any ideas? People have misunderstood my ...

Strip Comments from XML

I've encountered the need to remove comments of the form: <!-- Foo Bar --> I'd like to use a regular expression that matches anything (including line breaks) between the beginning and end 'delimiters.' What would a good regex be for this task? ...

Difficulty with Simple Regex (match prefix/suffix)

I'm try to develop a regex that will be used in a C# program.. My initial regex was: (?<=\()\w+(?=\)) Which successfully matches "(foo)" - matching but excluding from output the open and close parens, to produce simply "foo". However, if I modify the regex to: \[(?<=\()\w+(?=\))\] and I try to match against "[(foo)]" it fails to ...

Allowing Only Certain Characters In PHP

I need to check to see if a variable contains anything OTHER than a-z A-Z 0-9 and the "." character (full stop). Any help would be appreciated. ...

Sanitize html encoded text (#decimal notation) from AntiXSS v3 output

I am tying to make comments in a blog engine XSS-safe. Tried a lot of different approaches but find it very difficult. When I am displaying the comments I am first using Microsoft AntiXss 3.0 to html encode the whole thing. Then I am trying to html decode the safe tags using a whitelist approach. Been looking at Steve Downing's example...

preg_match_all() [function.preg-match-all]: Unknown modifier ']'

Using a few different patterns but they each come up with this error - so what's wrong? My shortest one to diagnose is: $pattern = "<img([^>]*[^/])>"; preg_match_all($pattern, $subject, $matches); Thanks ...