regex

How can I find repeated characters with a regex in Java?

Can anyone give me a Java regex to identify repeated characters in a string? I am only looking for characters that are repeated immediately and they can be letters or digits. Example: abccde <- looking for this (immediately repeating c's) abcdce <- not this (c's seperated by another character) ...

javascript regex question

I have a long string and I need to find instances of '#!#'+some text+'#!#' right now I have: string.replace(/(#!#*#!#)/g, function (m) {....}); I need the whole thing passed into a function like that so that I can replace them correctly. However, I want m to only be equal to what lies between the two #!#..I want this part....

How can I get a regex match to only be added once to the matches collection?

I have a string which has several html comments in it. I need to count the unique matches of an expression. For example, the string might be: var teststring = "<!--X1-->Hi<!--X1-->there<!--X2-->"; I currently use this to get the matches: var regex = new Regex("<!--X.-->"); var matches = regex.Matches(teststring); The results of ...

Matching fixed-format numbers in regex

Quick regex question (since i am horrible at it) I have a field that can only have either: XXXXXXXXXX or XXXXXX-XXXX where X is a real number. Bonus if the regex works well with PHP's regex functions. The Answer: Here's the code from RoBorg's answer, for those interested. if(!preg_match("/^\d{6}-?\d{4}$/", $var)) { // The entry...

Regular expression in PL/SQL

Hi All, I am using a regular expression to find out whether the user entered value is alpha numeric, allowing some special characters. I am using the following code which works fine: CREATE OR REPLACE PROCEDURE Validate_Inputstring (input_String IN VARCHAR2) AS BEGIN IF REGEXP_LIKE(input_String,'^[A-Z0-9a-z,+-?@]*$') THEN DB...

How can I remove unused, nested HTML span tags with a Perl regex?

I'm trying to remove unused spans (i.e. those with no attribute) from HTML files, having already cleaned up all the attributes I didn't want with other regular expressions. I'm having a problem with my regex not picking the correct pair of start and end tags to remove. my $a = 'a <span>b <span style="color:red;">c</span> d</span>e'; $a...

What is the best algorithm for arbitrary delimiter/escape character processing?

I'm a little surprised that there isn't some information on this on the web, and I keep finding that the problem is a little stickier than I thought. Here's the rules: You are starting with delimited/escaped data to split into an array. The delimiter is one arbitrary character The escape character is one arbitrary character Both the d...

Regex to match all HTML tags and tag content except <p> and </p>

I am looking for a regex to match all HTML tags, except <p> and </p> that includes the tag content. I am developing in ColdFusion. There was an earlier post about matching tags except <p> and </p>, but I need to grab everything between the tags as well. For instance, the following should match in their entirety: <a href="http://www.goo...

Regex to match domain...

Having trouble figuring this out and feeling quite stupid... I have many urls like this /imagebuilder-ptop.asp?imgCode=166 all I need is a regex that will match /imagebuilder-(ANTHING WHATSOEVER) If is it /imagebuilder-lkd fa;lsdfh adhf alkdfhdfh I want to match it...anything. ...

Matching parts of URIs with Regular Expressions

I want to match this url /Real_estate_Listing_Detail.asp?PropID=245 with the ability to EXCEPT PropID numbers... In other words, Match /Real_estate_Listing_Detail.asp?PropID=ANY NUMBER HERE, except, 286,289,290,180 Thanks in advance... this shouldnt be as hard as I make it... This is for a wordpress plugin, so a single line experss...

Regex to match a string with an even number of quotes

I came up with: ([^"]*["][^"]*["][^"]*)* It works in all cases except against the empty string. I thought it would work because the last star matches the previous token zero or more times. Any ideas? Also if there's a much better way of doing this please let me know and explain it in detail. The solution must be a regex as the place ...

C# - Processing html tag attributes

I'm getting some html data from remote server and before displaying it in the UI of application i need to make some changes, i.e. delete counters, replace links, etc. Removing some tag with contents and changing specific link is not a big deal, but when it comes to some advanced processing, i have some problems.There is a need to replace...

Regexp for matching numbers and units in an HTML fragment?

I'm trying to make a regexp that will match numbers, excluding numbers that are part of other words or numbers inside certain html tags. The part for matching numbers works well but I can't figure out how to find the numbers inside the html. Current code: //number regexp part var prefix = '\\b()';//for future use var baseNumber = '((\\...

Does this regex in PHP actually work?

Hello all, I am hoping the regular expression experts can tell me why this is going wrong: This regex: $pattern = '/(?<percent>[0-9]{1,3}\.[0-9]{1,2})% of (?<filesize>.+) at/'; Should match this sort of string: [download] 87.1% of 4.40M at 107.90k/s ETA 00:05 [download] 89.0% of 4.40M at 107.88k/s ETA 00:04 [download] 91.4% of 4....

date regex

i am trying to validate a date in c# in the format "yyyy/mm/dd". is it even possible (using regex) to validate that there aren't 30 days in february? ...

how to write this regular expression?

an 20 - 24 char long alphanumeric string with no spaces and no symbols that has at least 2 digits AAAAAAAAAAAAAAAAAAAA - not valid AAAAAA0AAAAAAAAA0AAA - valid AAAAAA01AAAAAAAAA0AAA - valid AAAAAA0AAAAAAAAA0AAA@ - not valid ...

Preference to one match in Regex when overlapping matches exist?

I have a regular expression that matches x OR y condition. Sometimes those matches overlap and I want to give preference to one of the conditions. Here is my test case. Regex: X[^\w]*\>|\>[^\w]*X Input: Soup > X > Alphabet Alphabet Soup > X X > Alphabet Soup Matches: The first highlighted match (yellow) should be X...

What's the most compact version of "match everything but these strings" in the shell or regex?

Linux: I want to list all the files in a directory and within its subdirectories, except some strings. For that, I've been using a combination of find/grep/shell globbing. For instance, I want to list all files except those in the directories ./bin ./lib ./resources I understand this can be done as shown in this question and this othe...

Getting the value of href attributes in all <a> tags on a html file with Python

I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines(). Currently I have this code that uses regex (I'm not very good at it) to search for links in every line: for line...

Regex help

If I had a div in HTML that had class="blah user_foo", whats the Match() regex to get the 'foo' bit? ...