regex

How to convet a string to pieces with PHP or regex?

I have different outputs of $slider['image']and two examples are followings. The first one has <p> and </p> at the beginning and at the end. In the second one, all img tag has <p> and </p> tags. UPDATE <p><span>Homepage</span><img src="../../assets/images/prints/print2_600x300.gif" alt="" width="600" height="300"> <span>Content Page...

Prevent SQL injection from form-generated SQL - NO PreparedStmts

Hi all, I have a search table where user will be able to filter results with a filter of the type: Field [Name], Value [John], Remove Rule Field [Surname], Value [Blake], Remove Rule Field [Has Children], Value [Yes], Remove Rule Add Rule So the user will be able to set an arbitrary set of filters, which will result essentially in a...

mod_rewrite page beautifying

So I'm stuck. I'm not very good with mod_rewrite or regular expressions in general, and this is giving me problems. I need to redirect url's like domain.com/view/Some_Article_Name.html to domain.com/index.php?p=view&id=Some_Article_Name The rule that I have now works fine, but it also rewrites for all my stylesheets and images and st...

Why does this preg_match not return 1?

I've been looking at this code and it's supposed to match my $input string and in $matches[0] store 'testing' $input = ':testing'; $r = preg_match('/^(?<=\:).+/',$input,$matches); What's wrong with it? ...

The case of the sneaky backslash - Regex

I'm missing something very obvious here, but I just cant see it. I've got: string input = @"999\abc.txt"; string pattern = @"\\(.*)"; string output = Regex.Match(input,pattern).ToString(); Console.WriteLine(output); My result is: \abc.txt I don't want the slash and cant figure out why it's sneaking into the output. I tried flippin...

PHP RegEx specify characters that I DO want?

How would I strip out all characters from a string that does NOT contain: [a-zA-Z0-9\-\/_] ? In other words, I'd like to specify what I DO want rather than what I don't. Thanks. ...

regex for shortforms

I need a regex (JavaScript) which will extract shortforms from a string for example from below string Hibbs' essays in progress include "Anselm's Sacramental Imagination," "W.E.B. DuBois and Socratic Questioning," and "Everything That Rises Must Converge: Aquinas's Theological Re-formation of the Cardinal Virtues." it will match ...

OWASP Regex Repository: Is this regex correct?

I was looking at the regular expression for validating various data types from the (OWASP Regex Repository). One of the regular expressions in there is called safetext and looks like: ^[a-zA-Z0-9\s.\-]+$ My first question is: Is this regular expression correct? complementary question If this Regex Repository any good at all? UPDA...

Need Regex for to match special situations

I'm desperately searching for regular expressions that match these scenarios: 1) Match alternating chars I've a string like "This is my foobababababaf string" - and I want to match "babababa" Only thing I know is the length of the fragment to search - I don't know what chars/digits that might be - but they are alternating. I've reall...

RegEx Pattern that matches positive or negative values (e.g "1.2", "-2.8", "7.8", -22.8")

decimal seperator is a dot, followed by max one digit! No range specified. Thanks guys! ...

Matching a Repeating Sub Series using a Regular Expression with PowerShell

I have a text file that lists the names of a large number of Excel spreadsheets, and the names of the files that are linked to from the spreadsheets. In simplified form it looks like this: "Parent File1.xls" Link: ChildFileA.xls Link: ChildFileB.xls "ParentFile2.xls" "ParentFile3.xls" Blah Link: ChildFileC.xls Link: ChildFi...

Advanced replace in C#

Hi, I like to replace some attributes inside a xml (string) with c#. Example xml: <items> <item x="15" y="25"> <item y="10" x="30"></item> </item> <item x="5" y="60"></item> <item y="100" x="10"></item> </items> In this case I like to change the x-attributes to the combined value of x and y. Result xml: <items> <item...

Regular Expression for exclude something that has specific word inside bracked (MySQL)

This Regular expression if for MySQL query: I want to exclude this row because it has 'something' in side the bracket "bla bla bla bla bla bla (bla bla bla something)" However I want to include this row, because it does not have 'something' inside the bracket "bla bla bla (bla bla bla)" I tried this query but it didnt work. SELECT * ...

Does this e-mail-regex exclude valid addresses?

I tried to create a regular expression which catches all RFC-valid addresses but it's ok if some false-positives come through (though hopefully not so many). This is waht I came up so far: /^\b\S+@\S+\.[^\s@]{2,}\b$/ Is there any RFC-valid address which doesn't match against this expression or do you have any suggestions to improve it...

What would be the PHP equivalent of this Perl regex?

What would be the PHP equivalent of this Perl regex? if (/^([a-z0-9-]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ and $1 ne "global" and $1 ne "") { print " <tr>\n"; print " <td>$1</td>\n"; print " <td>$2</td>\n"; print " <td>$3</td>\n"; print " <td>$4</td>\n"; print " <td>$5</td>...

Javascript Regex multiple group matches in pattern

I have a question for a Javascript regex ninja: How could I simplify my variable creation from a string using regex grouping? I currently have it working without using any grouping, but I would love to see a better way! The string is: var url = 'resources/css/main.css?detect=#information{width:300px;}'; The code that works is: var s...

Negative look ahead java

I need an expression to capture a string like this "A"[A string that is NOT atleast 5 and atmost 6 digits]"B", In other words capture anything that is NOT the following A[0-9][0-9][0-9][0-9][0-9]B A[0-9][0-9][0-9][0-9][0-9][0-9]B I have tried the negative look ahead regex = "a((?![0-9]{5,6}).)*d" ; But it fails to capture all scen...

linker error when using tr1::regex

Hello. I've got a program that uses tr1::regex, and while it compiles, it gives me very verbose linker errors. Here's my header file MapObject.hpp: #include <iostream> #include <string> #include <tr1/regex> #include "phBaseObject.hpp" using std::string; namespace phObject { class MapObject: public phBaseObject { priva...

RegEx/Javascript validation: Don't allow comma as a valid character

I'm doing Javascript validation on my number fields. I'm using RegEx to do this - first time RegEx user. I need the user to only enter numbers and decimals, but not commas. (i.e. 3600.00 is okay, but 3,600.00 is not). I can't figure out how to eliminate the commas as an accepted character. Any help is appreciated. Thanks! ...

RegEx Help in Ruby

My sample file is like below: H343423 Something1 Something2 C343423 0 A23423432 asdfasdf sdfs #2342323 I have the following regex: if (line =~ /^[HC]\d+\s/) != nil puts line end Basically I want to read everything that starts with H or C and is fol...