regex

How to group only words, no spaces?

Hi, i want group all words without white space e.g.: I like stackoverflow [0]I [1]like [2]stackoverflow i know its a easy regex but i forgot how i do that xP. ...

Regex for port numbers in Android?

Consider a regex for testing port numbers. (6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}) This is not valid in Android. Any idea what a port number regex should look like in Android? ...

In Ruby, what is the most correct way to use Regular Expression to match a single digit and **nothing else**?

(Update: this question's main focus is to test the "nothing else" part) Given a string s, which can contain anything, what is the most correct regexp in Ruby to check whether it is a single digit and nothing else? (a single digit and only a single digit). ...

How to change this Ruby regex to also include underlines?

At the moment I am using this line to take a string and extract only the letters from it: string.scan(/[a-zA-Z]/).to_s How do I modify this so that the underline character, "_", is also included? Thanks for reading. ...

How to split a String in Java, ignoring multiple successive tokens

I'm trying to parse arguments for a command, but if I were to put multiple spaces in a row, String.split() will leave empty Strings in the result array. Is there a way I can get rid of this? For example: "abc 123".split(" ") results in {"abc", "", "", "", "", "123"} but what I really want is {"abc", "123"} ...

Regex to match 'lol' to 'lolllll' and 'omg' to 'omggg', etc..

Hey there, I love regular expressions, but I'm just not good at them at all. I have a list of some 400 shortened words such as lol, omg, lmao...etc. Whenever someone types one of these shortened words, it is replaced with its English counterpart ([laughter], or something to that effect). Anyway, people are annoying and type these shor...

Regex for a string

Hi, It would be great if someone could provide me the Regular expression for the following string. Sample 1: <div>abc</div><br> Sample 2: <div>abc</div></div></div></div></div><br> As you can see in the samples provided above, I need to match the string no matter how many number of </div> occurs. If there occurs any other string bet...

How do I extract certain digits from raw input in Python?

Let's say I ask a users for some random letters and numbers. let's say they gave me 1254jf4h. How would I take the letters jfh and convert them inter a separate variable and then take the numbers 12544 and make them in a separate variable? ...

Is it possible to match a regex against binary data in .net?

I know that I can use regex to match substrings in a string, but is it possible to match some patterns in binary data using regex? If so then in what format should the binary data be - binary array, stream, or something else? edit: well to explain i have binary data that shouldnt have some strings inside but the data itself is binar...

How to change file names using regular expressions in Python?

I have a directory which contains subdirectories which contain files. All the file names have a prefix which I want to eliminate. The prefix is not exactly the same among all the files, but I have a regular expression that represents exactly the language of these prefixes. I'm trying to write a script in Python to change the name of each...

How to write this Regular Expression

How do i write a regular expression which accepts only value "1" in the textbox and it should not accept zero or greter than "1" ...

Split string of 2 words in separate words [but sometimes there is only word in the string...]

I have strings like "AMS.I-I.D. ver.5" and "AM0011 ver. 2", of which the "ver. *" needs to be stripped. I have done that with: (^A.*)(ver.\s\d{1,2}) The problem occurs when there is no version number like "AM0003". How can I make the (ver.\s\d{1,2}) part optional? ...

Can't figure out what's wrong with this regex.

Regex newbie here. There's a (broken) plugin for the forum software I use that I'm attempting to fix. It's generating the following regex: /(?:\s|^)\[(?:\:\)\]|;\)\])(?:\s|$)/m ... to replace all instances of [:)] or [;)] in a block of text using preg_replace(). However, it's not replacing the instances of [:)] or [;)]. Any ideas? ED...

Find longest repeating substring in JavaScript using regular expressions

I'd like to find the longest repeating string within a string, implemented in JavaScript and using a regular-expression based approach. I have an PHP implementation that, when directly ported to JavaScript, doesn't work. The PHP implementation is taken from an answer to the question "Find longest repeating strings?": preg_match_all('/...

Greedy, Non-Greedy, All-Greedy Matching in C# Regex

Hi, How can I get all the matches in the following example: // Only "abcd" is matched MatchCollection greedyMatches = Regex.Matches("abcd", @"ab.*"); // Only "ab" is matched MatchCollection lazyMatches = Regex.Matches("abcd", @"ab.*?"); // How can I get all matches: "ab", "abc", "abcd" Thanks. Peter P.S.: I want to have the all...

How to capture results of regex and replace patterns in bash

Bash scripting does my head in. I have searched for regex assignment, but not really finding answers I understand. I have files in a directory. I need to loop through the files and check if they fit certain criteria. File names under a certain sequence need to have their sequence increased. Those over a certain sequence need to trigger ...

turn urls into links but not break images src or Flash embeds in php

I had a code that turned http:// in to <a links. the issue with it was that it would break images and flash players. It was using Regex. Does anyone know of a Regex code that would do this? ...

Write regular expression for C numerical literals

My homework is to write a regular expression representing the language of numerical literals from C programming language. I can use l for letter, d for digit, a for +, m for -, and p for point. Assume that there are no limits on the number of consecutive digits in any part of the expression. Some of the examples of valid numerical liter...

Unclosed tags in string

Hi. In my string I have some unclosed html tags. For example <div><p></p> or <p><b></p> I'm using asp.net c#. Maybe regex can works. ...

Need a regular expression for matching specific sentence format

Hi everyone. I need a regular expression to match a very specific sentence format. The format is as follow: word(that can contain ,()[]&^%# and whitespace), word(that can contain ,()[]&^%# and whitespace), word(that can contain ,()[]&^%# and whitespace) So basically it's a word, word, word but every word can contain some special charac...