regex

Simple C# Regex

I'm trying to regex-out a hash given in a string from a web-service response. The response given is in the format: Write this code down, this is your id for the following tasks: P+3zLI8x1AokfbZ1jXat9g== You will need to enter the code in each of the following steps. The next task is somewhat simpler, and demonstrates the process of v...

awk: Either modify or append a line, based on its existence

I have a small awk script that does some in-place file modifications (to a Java .properties file, to give you an idea). This is part of a deployment script affecting a bunch of users. I want to be able to set defaults, leaving the rest of the file at the user's preferences. This means appending a configuration line if it is missing, mod...

How can I extract a varying number of groups of digits from a Perl string?

I am attempting to parse a string in Perl with the format: Messages pushed to the Order Book queues 123691 121574 146343 103046 161253 I want to access the numbers at the end of the string so intend to do a match like /(\d+)/s My issue is that the number of values at the end contain a variable number of strings. What is the best wa...

Splitting a String (especially in Java with java.util.regex or something else) ...

Does anyone know how to split a string on a character taking into account its escape sequence? For example, if the character is ':', "a:b" is split into two parts ("a" and "b"), whereas "a\:b" is not split at all. I think this is hard (impossible?) to do with regular expressions. Thank you in advance, Kedar ...

Keep formatting of textbox after a postback?

I am building a HTML scrubber basically an internal tool for scrubbing a problematic html page. I am building the tool as a web app using ASP.NET 3.5. It consists of a button and two multiline textboxes. I am programming it so you paste in the HTML you want scrubbed into the top box. Hit the button and the scrubbed HTML shows up in t...

Regex match a hostname -- not including the TLD

I need to match a host name--but don't want the tld: example.com =~ /regex/ => example sub.example.com =~ /regex/ => sub.example sub.sub.example.com =~ /regex/ => sub.sub.example Any help with the regex? Thanks. ...

Print regex matches in java

So I have an IP address as a string. I have this regex (\d{1-3})\.(\d{1-3})\.(\d{1-3})\.(\d{1-3}) How do I print the matching groups? Thanks! ...

How do I remove colons from a list of MAC addresses?

I'm having a hard time trying to remove the colons in a list of MAC addresses. My file: 00:21:5A:28:62:BF 00:24:81:0A:04:44 Expected Output: 00215A2862BF 0024810A0444 Any ideas on how could I do this? Thanks a lot in advance. ...

How would I remove all commas not inside parenthesis from a string in C#?

I have a mathparser that can do functions like "IntPow(3,2)". If a user pastes "1,000,000" and then adds a plus symbol, making the full equation "1,000,000+IntPow(3,2)" the parser fails because it does not work with numbers that contain commas. I need to remove the commas from the "1,000,000", but not from the "IntPow(3,2)" because Int...

Regular expression syntax In PHP to extract all instances of a format.

I am attempting to extract all instances of a particular format from a string: I am wondering if my new Sony [PT# 123456ABC; Sony] has this feature but my friend says the new Toshiba [PT# AD-3232hjk; Toshiba] has this feature. I would like to extract: [PT# 123456ABC; Sony] [PT# AD-3232hjk; Toshiba] As you can see here, t...

Apache mod rewrite simple redirect

I want requests to my site to work as follows: http://example.com/ would pull up the index.php file (the current default behavior) ideally without displaying the index.php http://example.com/foo.php would pull up foo.php as would be expected http://example.com/blerg would redirect to http://example.com/bar.php?code=blerg I have the f...

How to match subdirectories in RewriteCond?

Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that is, does not apply following rewrite to all URLs that start with /foo/. RewriteCond %{REQUEST_URI} !^/foo/bar/ On the other hand does not work as I expect. URLs that begin with /foo/bar/ are still being rewrited. How do I en...

Wondering how to do PHP explode over every other word

Lets say I have a string - $string = "This is my test case for an example." If I do explode based on ' ' I get an Array('This','is','my','test','case','for','an','example.'); What I want is an explode for every other space: Array('This is','my test','case for','an example.'). The string may have an odd # of words, so the last item in ...

Stripping everything but alphanumeric chars from a string in PHP

I'd like a regexp or other string which can replace everything except alphanumeric chars (a-z and 0-9) from a string. All things such as ,@#$(@*810 should be stripped. Any ideas? Edit: I now need this to strip everything but allow dots, so everything but a-z, 1-9, .. Ideas? ...

Using a regex to determine domain using JavaScript

Hi All, If, as here at work, we have test, staging and production environments, such as: http://test.my-happy-work.com http://staging.my-happy-work.com http://www.my-happy-work.com I am writing some javascript that will redirect the browser to a url such as: http://[environment].my-happy-work.com/my-happy-video I need to be able t...

Regular expressions C# - is it possible to extract matches while matching?

Say, I have a string that I need to verify the correct format of; e.g. RR1234566-001 (2 letters, 7 digits, dash, 1 or more digits). I use something like: Regex regex = new Regex(patternString); if (regex.IsMatch(stringToMatch)) { return true; } else { return false; ...

Regular expression to replace _

I have this pattern a,abc_def_eghi 1,234_556 5,567_987_ghi I want to replace the first _ with a ",". I know %s/old/new/g to replace contents in vim. Result a,abc,def_eghi 1,234,556 5,567,987_ghi Could you suggest some alternatives to go about it ...

Use C# regex to convert casing in a string

Hi, how can I convert this string: bKk_035A_paint-House_V003 to BKK_035a_paint-House_v003 with a regular expression (e.g. Regex.Replace)? This regex matches the string: ^(?<Group1>[a-z][a-z0-9]{1,2})_(?<Group2>\d{3}[a-z]{0,2})_(?<Group3>[a-z-]+)_(?<Group4>v\d{3,5})$ Group1 = uppercase Group2 = lowercase Group3 = unchanged ...

What's the most efficient way to find one of several substrings in Python?

Hello, I have a list of possible substrings, e.g. ['cat', 'fish', 'dog']. In practice the list contains hundreds of entries. I'm processing a string, and what I'm looking for is to find the index of first appearance of any of these substrings. To clarify, for '012cat' the result is 3, and for '0123dog789cat' the result is 4. I also...

Best regex pattern for matching non SP1 IE6 in user agent string?

I needed some code to match all IE6 versions that are not SP1 (part of Windows XP SP2, confusing eh). This is to turn gzip off for versions of IE that do not handle it properly. The best I have come up with is: MSIE [1-6]\.(?!.*?SV1) Does anyone have a better pattern? What the regex above does is basically do a lookahead to make sur...