Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 58 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Regex Help
PostPosted: Fri Aug 29, 2008 13:45 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Okay, so I've got a string like this:
Code:
906||443&&43||12&&122

The things between the numbers are 'and' or 'or' operators. I can find them using this regex:
Code:
(\|\||&&)


How do I match and replace only, say, the 3rd match (in this case, '||')?

Bonus points if you can do it using javascript's string.replace function, but if not I should be able to figure it out from what you tell me.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 13:59 
User avatar

Joined: 30th Mar, 2008
Posts: 14321
Location: Shropshire, UK
Not sure you can do this and keep it scalable, to be honest. You can hardcode it, as follows:

.*(?:\|\||&&).*(?:\|\||&&).*(\|\||&&)

The ?: at the start of the parentheses tells the PCRE engine to not store those subpatterns so it'd only match the third one in this case.

At least, I think that should work.

You're probably better off writing some JS/PHP to split the string up into bits using the operators as delimiters, and then process them like that.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:03 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Really? Nads. Ta.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:14 
User avatar
Heavy Metal Tough Guy

Joined: 31st Mar, 2008
Posts: 6584
Something like:

Code:
$string =~ s/(\|\||&&)/--$instance?$&:'blah'/eg


works in perl. God knows if there are equivalents in PHP.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:14 
User avatar

Joined: 30th Mar, 2008
Posts: 14321
Location: Shropshire, UK
I'm no regex expert so wait and see if someone else weighs in, but I remember wanting to do similar things in the past and finding that they're just not capable of doing repetitions in the way you want them to.

Squirt wrote:
Something like:

Code:
$string =~ s/(\|\||&&)/--$instance?$&:'blah'/eg


works in perl. God knows if there are equivalents in PHP.

Which bit is it in that that tells it to only process the third one? Is it the -- ?


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:16 
Excellent Member. Haha! Member

Joined: 31st Mar, 2008
Posts: 116
Gazchap and I are working along similar lines but I'm apparently more bored at work than he ;)

Shame you didn't want the stuff between your delimiters as that's easy to explode a string to an array using a regexp.

Making this function grab the nth element is an exercise left to the reader.

Code:
   function grim() {
      input = "906||443&&43||12&&122";

      re = /(\|\||\&\&)/g;
   
      loc = 0;

      while (loc > -1) {
         match = re(input);
         loc = re.lastIndex;
         if (loc == 0) {
            // not found
            break;
         }

         token = match[1];
         alert("found at " + loc + ": " + token);
      }
   }

_________________
Image
<shin> we've got some pegging to do


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:17 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
What I wanted to do was change the nth && or || to it's opposite. I've done it in Javascript - it works, but it's ugly.
Code:
    code = code.substr(2);
    carr = code.split(/(\|\||&&)/gi);
    if (carr[((count*2)-1)] == "||") {
        carr[((count*2)-1)] = "&&";
    } else {
        carr[((count*2)-1)] = "||";
    }
    code = carr.join("");

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:19 
User avatar
Heavy Metal Tough Guy

Joined: 31st Mar, 2008
Posts: 6584
GazChap wrote:
I'm no regex expert so wait and see if someone else weighs in, but I remember wanting to do similar things in the past and finding that they're just not capable of doing repetitions in the way you want them to.

Squirt wrote:
Something like:

Code:
$string =~ s/(\|\||&&)/--$instance?$&:'blah'/eg


works in perl. God knows if there are equivalents in PHP.

Which bit is it in that that tells it to only process the third one? Is it the -- ?



Ooops, you have to set $instance =3 somewhere above.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:20 
Excellent Member. Haha! Member

Joined: 31st Mar, 2008
Posts: 116
Squirt wrote:
Ooops, you have to set $instance =3 somewhere above.


Executing code in regexps is simultaneously beautiful and hideous at the same time.

Just like the rest of Perl I guess :)

_________________
Image
<shin> we've got some pegging to do


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:21 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
JamesOff wrote:
Shame you didn't want the stuff between your delimiters as that's easy to explode a string to an array using a regexp.

Ha, sorry, I did :)

Thanks for all your help, chums!

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:24 
User avatar
Heavy Metal Tough Guy

Joined: 31st Mar, 2008
Posts: 6584
There is nothing like a programming language that looks as if you've accidentally opened an image file in your text editor, but still actually does stuff.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:27 
User avatar

Joined: 30th Mar, 2008
Posts: 14321
Location: Shropshire, UK
Real nerds code in Brainfuck.

Hello World in Brainfuck:
Code:
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:34 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Code:
HAI
CAN HAS STDIO?
VISIBLE "Hello world"
KTHXBYE

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:38 
Excellent Member. Haha! Member

Joined: 31st Mar, 2008
Posts: 116
The lolcats language looks like you accidentally opened a 3 year old's head instead :(

_________________
Image
<shin> we've got some pegging to do


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:42 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49237
Pfft. Regex's are for losers. What you want is nested substrings.

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 14:53 

Joined: 30th Mar, 2008
Posts: 8679
Craster wrote:
Pfft. Regex's are for losers. What you want is nested substrings.


:this:


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 15:08 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Craster wrote:
Pfft. Regex's are for losers. What you want is nested substrings.

I'm not sure what I wanted is possible with substrings, because of the && or || split.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Aug 29, 2008 15:11 
Excellent Member. Haha! Member

Joined: 31st Mar, 2008
Posts: 116
Grim... wrote:
I'm not sure what I wanted is possible with substrings, because of the && or || split.


Take that, you substring-using suckers!

*text-processing religious war goes here*

_________________
Image
<shin> we've got some pegging to do


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Sun Aug 31, 2008 0:39 
Excellent Member

Joined: 30th Mar, 2008
Posts: 112
Had to get help with the regex (I was *nearly* there), but this does the job:

Code:
function swapPipeAmpersand(str, n) {
   
   // Locate nth pipe/ampersand set and replace with placeholders
   var reg = new RegExp("^((?:[0-9]+[\\|&]{2}){" + (n-1) + "})([0-9]+)[\\|&]{2}");
   var out = str.replace(reg,"$1$2..");
      
   // Work out what the original string contained, and replace with opposite
   if (str.charAt(out.indexOf('.')) == '|') {
      return out.replace(/[.]/g, '&');
   } else {
      return out.replace(/[.]/g, '|');
   }
}

alert(swapPipeAmpersand("23||45||45||56||67", 4));


Since it's pretty much impossible to know exactly what it is that the regex has matched without iterating through all of the matches, the best I can do is replace the pipe/ampersand set with a placeholder (two full stops), then look at the original string at that position to work out what the function replaced in order to swap it. Splitting the string into an array is probably much faster.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Sun Aug 31, 2008 1:01 
User avatar
MR EXCELLENT FACE

Joined: 30th Mar, 2008
Posts: 2568
I'm pretty sure a problem like this is non-regular, as it requires a notion of memory over previous matches* and so can't be matched by a standard regular language.

ie: Do it GazChaps way or don't do it at all using a Regex. You're using a screwdriver for a hammer problem. You can smack the nail in with the blunt end but it'll hurt like hell to do so.

* memory as in things wot happened, rather than RAM.


edit: Easiest way is just to loop over the pattern you provided, and only do something on the third match. That's like what, to extra lines? And if you want to make it 20th instead of 3rd you just change one number.

_________________
This man is bound by law to clear the snow away


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Dec 21, 2012 17:13 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
New to regex, I want to replace all characters in a string that are not numeric or are not a line feed character.

Something like [^0-9]\r

But not quite, as that only matches non numeric and a line feed (I think).

How do I use 'or' in regex?
Help?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Dec 21, 2012 17:37 
User avatar
ugvm'er at heart...

Joined: 4th Mar, 2010
Posts: 22366
([^0-9])|(\r) I think. You may not need the brackets in fact.

"|" is or IIRC


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Dec 21, 2012 18:00 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
Trooper wrote:
([^0-9])|(\r)
That means "all the characters that are anything other than a 0-9, OR are \r". That's not what you want to protect \r too.

[^0-9\r] is the pattern you want, I think. You can kuldge anything you want into square brackets like that. [a-zA-Z0-9] is a common pattern, for example.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Fri Dec 21, 2012 18:35 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Cheers guys, I'll try both of those on Monday.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 13:35 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Stupid Regex.

I'm trying to extract the RTW from the below phrase by selecting everything except that bit and replacing it with nothing:
123456-Mr Smith-RTW(27062013 150729).pdf

(^.*?)-(.*?)- seems to grab "123456-Mr Smith-"
\((.*)\).pdf grabs the "(27062013 150729).pdf" bit, but how can I combine these to grab both at the same time, when the RTW could be any combination of characters.

The first bit could be any characters, but the constants in this changing filename will be the two hyphens, and the datetime in parentheses plus .pdf

Or is it easier to just run the whole thing through a replacement function twice?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 13:42 
User avatar
MR EXCELLENT FACE

Joined: 30th Mar, 2008
Posts: 2568
Mr Russell wrote:
Stupid Regex.

I'm trying to extract the RTW from the below phrase by selecting everything except that bit and replacing it with nothing:
123456-Mr Smith-RTW(27062013 150729).pdf

(^.*?)-(.*?)- seems to grab "123456-Mr Smith-"
\((.*)\).pdf grabs the "(27062013 150729).pdf" bit, but how can I combine these to grab both at the same time, when the RTW could be any combination of characters.

The first bit could be any characters, but the constants in this changing filename will be the two hyphens, and the datetime in parentheses plus .pdf

Or is it easier to just run the whole thing through a replacement function twice?


String split on "-" and take the right most one, then split on the ( and take the leftmost one. What're those quotes about using regex and having two problems, or everything being a nail?

_________________
This man is bound by law to clear the snow away


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 14:00 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Mr Russell wrote:
Or is it easier to just run the whole thing through a replacement function twice?

It's hard to say without some more examples of file names - is it always -AAA that you need? Or can it have numbers in, too? Can the length of that change? What language are you doing it in?

The "loosest" possible way to get those three characters is probably this:
Code:
-(.{3})\(


Image

Fiddle with it

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 14:10 
User avatar
Unpossible!

Joined: 27th Jun, 2008
Posts: 38597
Use it once every 10 full tanks and it'll help no end.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:10 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Grim... wrote:
Mr Russell wrote:
Or is it easier to just run the whole thing through a replacement function twice?

It's hard to say without some more examples of file names - is it always -AAA that you need? Or can it have numbers in, too? Can the length of that change? What language are you doing it in?

The "loosest" possible way to get those three characters is probably this:
Code:
-(.{3})\(


Image

Fiddle with it

No, the 'bit I need' could be any length and any combination of characters.

The only constants are that it will be data hyphen data hyphen NEEDED BIT Brackets Data Brackets.pdf

Pod, I'm trying to run this through an Eval() function in ASPX so I can only use one line, otherwise I'd pre-process the lot using aspx.

I'll have a go with the fiddle, thanks both.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:11 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Can the data have brackets or hyphens in?

If not, you need
Code:
-(.+)\(


If so, you're fucked ;)

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:15 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Grim... wrote:
Can the data have brackets or hyphens in?

If not, you need
Code:
-(.+)\(


If so, you're fucked ;)

Fortunately not.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:18 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Grim... wrote:
Can the data have brackets or hyphens in?

If not, you need
Code:
-(.+)\(


If so, you're fucked ;)

Ooh, so close...
Attachment:
Untitled.png


You do not have the required permissions to view the files attached to this post.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:22 
User avatar
Heavy Metal Tough Guy

Joined: 31st Mar, 2008
Posts: 6584
Code:
-([^-]+)\(
?


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:26 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Oh, okay:
Code:
.*-(.+)\(


That's fine for double-barrelled surnames, too.

Or what Squirt said.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:27 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Squirt wrote:
Code:
-([^-]+)\(
?
Attachment:
Untitled.png


You do not have the required permissions to view the files attached to this post.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:28 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Grim... wrote:
Oh, okay:
Code:
.*-(.+)\(


That's fine for double-barrelled surnames, too.
Attachment:
Untitled.png


You do not have the required permissions to view the files attached to this post.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:29 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
In either of those situations, just pull out group 1.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:30 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
(^.*?)-(.*?)- [but not this bit] \((.*)\).pdf

I kind of need to combine the first and last, where the [but not this bit] can be anything (but not a hyphen or parenth)

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:32 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Hang on - do you want to find out what the bit before the bracket is, or remove it and glue what's left back together (ie. replace it with nothing)?

In other words, with
Code:
21321-Carrie Lzynch-RTW(24324 423423).pdf
should it return
Code:
RTW
or
Code:
21321-Carrie Lzynch-(24324 423423).pdf
?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:36 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
I want to turn "123456-Mr Smith-RTW(28062013 141130).pdf" into "RTW"

This is my existing code with the above as PDFFilename:
Code:
<asp:Label ID="Label1" runat="server" Text='<%# Regex.Replace(Eval("PDFFilename"), "\((.*)\).pdf", "")%>'></asp:Label>


...that replaces the data in the brackets at the end, including the brackets with nothing, and leaves "123456-Mr Smith-RTW"

I am now trying to get rid of the data hyphen data hyphen before that last bit of data to leave just "RTW" (or whatever string of characters rtw happens to be).

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:38 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
I am aware the inclusion of a Regexreplace routine may now complicate things, sorry for being unclear before.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:39 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Take either mine or Squirt's regex, stick
Code:
.*$
on the end and replace it with
Code:
"$1"
rather than
Code:
""


That might not be how ASP does it, but it'll be something like that.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:39 
User avatar
Heavy Metal Tough Guy

Joined: 31st Mar, 2008
Posts: 6584
Lookaheads and behinds?

Code:
(?<=-)[^-]{3}(?=\()


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:44 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
This should do the trick:

Code:
<asp:Label ID="Label1" runat="server" Text='<%# Regex.Replace(Eval("PDFFilename"), "^.*-(.+)\(.*$", "$1")%>'></asp:Label>

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:46 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Squirt wrote:
Lookaheads and behinds?

Code:
(?<=-)[^-]{3}(?=\()

Very close if I use Regex.Match instead of Replace, but only matches the anydata bit where it is three characters.

Grim... your
Code:
<asp:Label ID="Label1" runat="server" Text='<%# Regex.Replace(Eval("PDFFilename"), "^.*-(.+)\(.*$", "$1")%>'></asp:Label>
seems to be spot on, thank you!

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:48 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
I'm not exactly sure why, mind, as when I paste the regex bit into my regex tester it matches the whole string, but OK!

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:49 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12328
Thanks to everyone else who melded their mind around this as well :)

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:49 
User avatar
Heavy Metal Tough Guy

Joined: 31st Mar, 2008
Posts: 6584
Ahh, can the RTW it be any length?

Then
Code:
(?<=-)[^-]+(?=\()


will do it.

Use mine, not Grim...'s. Mine has question marks in.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:51 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Mr Russell wrote:
I'm not exactly sure why, mind, as when I paste the regex bit into my regex tester it matches the whole string, but OK!

The brackets around the .+ mark it out as being a 'group'. So we matched the whole thing, and replaced it with that group (using $1). If there were two groups the next one would be $2, and so on.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Regex Help
PostPosted: Thu Jun 27, 2013 15:53 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69685
Location: Your Mum
Squirt wrote:
Use mine, not Grim...'s. Mine has question marks in.

Code:
^.*-([^-]+?)\(.*$
;)

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 58 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Columbo, Majestic-12 [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.