regex

Remove unmatched HTML tags in a string

Folks does anyone knows of a PHP function to remove unmatched HTML tags from a string. for example<div> This is a string <b> with an unmatched bold tag </div>. If there isnt one then help me buld one, maybe I can have a function that counts the number of opening tags and matching closing tags. If they are not even then remove the first o...

Getting contents of square brackets with regex, including nested ones

Is there any way to have this: [one[two]][three] And extract this with a regex? Array ( [0] => one[two] [1] => two [2] => three ...

Regex vs. Manual comparison. Which is faster?

Hello, in writing a scripting engine, I have functions like (psuedo-code) function is_whitespace?(char c){ return c==' ' || c=='\t' || c=='\r' || c=='\n'; } Well, my question is which is faster in most langugaes? That or using regex like function is_whitespace?(char c){ return regex_match('\s',c); } The chief languages I'm conc...

Passing string with (accidental) escape character loses character even though it's a raw string

I have a function with a python doctest that fails because one of the test input strings has a backslash that's treated like an escape character even though I've encoded the string as a raw string. My doctest looks like this: >>> infile = [ "Todo: fix me", "/** todo: fix", "* me", "*/", r"""//\todo stuff to fix""", "TODO f...

C# Regex: Capture everything up to...

I want to capture everything up to (not including) a # sign in a string. The # character may or may not be present (if it's not present, the whole string should be captured). What would the RegEx and C# code for this by? I've tried: ([^#]+)(?:#) but it doesn't seem to work. ...

Ruby regex match specific string with special conditions

I'm currently trying to parse a document into tokens with the help of regex. Currently I'm trying to match the keywords in the document. For example I have the following document: Func test() Return blablaFuncblabla EndFunc The keywords that needs to be matched is Func, Return and EndFunc. I've comed up with the following regex: (...

C# regex to validate "realistic" IP values

Regex that somewhat validates if a value has one of the following characteristics: 123-29-123-123.subdomain.zomg.com:8085 123.12.34.56:420 Unfortunately, I'm terrible at Regex, C#, google searches, and the differences between proper nouns and regular ones. It can be a lose approximation, in fact I would go with anything that has a : ...

Can PCRE regex match a null character?

I have a text source with nulls in it and I need to pull them out along with my regex pattern. Can regex even match a null character? I only realized I had them when my pattern refused to match and when I pasted it into Notepad++ it showed all the null characters. ...

Help with password complexity regex

I'm using the following regex to validate password complexity: /^.*(?=.{6,12})(?=.*[0-9]{2})(?=.*[A-Z]{2})(?=.*[a-z]{2}).*$/ In a nutshell: 2 lowercase, 2 uppercase, 2 numbers, min length is 6 and max length is 12. It works perfectly, except for the maximum length, when I'm using a minimum length as well. For example: /^.*(?=.{6,})...

Given the full path to a file, how do I get just the path without the filename?

Hello, Suppose I have a path in a string called '/home/user/directory/HelloWorld.txt'. I would like to remove the HelloWorld.txt, and end up with '/home/user/directory'. What regex would I need. ...

Add / remove a port number to/from a URL with REGEX in PHP

Hello guys, I've searched but was unable to find an existing regex function. Has anybody done this before? I wish to add a port number, or remove a potantially existing one from a url in php. To use in some functions which translate a given url to the secure one, unsecure one, etc. Now I need a second SSL secured site on the server so...

How do I remove duplicate characters and keep the unique one only in Perl?

How do I remove duplicate characters and keep the unique one only. For example, my input is: EFUAHUU UUUEUUUUH UJUJHHACDEFUCU Expected output is: EFUAH UEH UJHACDEF I came across perl -pe's/$1//g while/(.).*\/' which is wonderful but it is removing even the single occurrence of the character in output. ...

URL regex search and replace on MySQL (in WordPress)

Hello all, I have a WordPress blog with numerous URL's I wish to replace from this: http://www.oldwebsite.co.il/name/*.asp To this: http://www.newwebsite.com/?p=* For example, from this: http://oldwebsite.co.il/name/65971.asp To this: http://www.newwebsite.com/?p=65971 I believe the following plugin: http://urba...

Regex to validate JSON

I am looking for a Regex that allows me to validate json. I am very new to Regex's and i know enough that parsing with Regex is bad but can it be used to validate? ...

Why is this statement treated as a string instead of its result?

I am trying to perform some composition-based filtering on a large collection of strings (protein sequences). I wrote a group of three subroutines in order to take care of it, but I'm running into trouble in two ways - one minor, one major. The minor trouble is that when I use List::MoreUtils 'pairwise' I get warnings about using $a and...

Limiting input to specified regexp with uppercase chars in IE

I'm trying to limit what our users will be able to type in inputs, using javascript/jquery. Problem is, I have to limit this to Uppercase chars only, and numbers. Here's what I coded previously : $(input).keypress(function(e){ if ($(input).attr("class")=="populationReference"){ var ValidPat...

Finding All Characters Between Parentheses with a .NET Regex

I need to get all characters between '(' and ')' chars. var str = "dfgdgdfg (aaa.bbb) sfd (c) fdsdfg ( ,ddd (eee) )"; In this example, I need to get 3 strings: (aaa.bbb) (c) ( ,ddd (eee) ) What pattern I have to write? Please, help. ...

Regex for multi-line HTML comments (preg_match_all)

I have an html document with multiple commented-out PHP arrays, e.g.: <!-- Array ( [key] => 0 ) --> Using PHP, I need to somehow parse the HTML for only these comments (there are other comments that will need to be ignored) and extract the contents. I've been trying to use preg_match_all but my regex skills aren't up to much. Could an...

Regex Help with manipulating string

Hi, i am seriously struggling to get my head around regex. I have a sring with "iPhone: 52.973053,-0.021447" i want to extract the two numbers after the colon into two seperate strings so delimited by the comma. Can anyone help me? Cheers ...

C# RegEx - find html tags (div and anchor)

Hi I have to retrieve several div section (of specific class name "row ") with it's content, and additionally find all anchor tags (link urls) (with class "underline red bold"). Shortly speaing : get section of: <div class = "row "> ... (divs, tags ...) <a class="underline red bold" href="/searchClickThru?pid=prod56534895&amp;q=&amp;r...