Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6536 > unrolled thread
| Started by | Michael Joel <null@void.void> |
|---|---|
| First post | 2012-07-11 18:35 -0400 |
| Last post | 2012-07-11 23:27 -0400 |
| Articles | 9 — 4 participants |
Back to article view | Back to comp.lang.php
not understanding pattern matching Michael Joel <null@void.void> - 2012-07-11 18:35 -0400
Re: not understanding pattern matching Michael Fesser <netizen@gmx.de> - 2012-07-12 00:49 +0200
Re: not understanding pattern matching Michael Joel <null@void.void> - 2012-07-11 19:11 -0400
Re: not understanding pattern matching Michael Fesser <netizen@gmx.de> - 2012-07-12 01:26 +0200
Re: not understanding pattern matching Michael Joel <null@void.void> - 2012-07-11 19:31 -0400
Re: not understanding pattern matching BootNic <bootnic.bounce@gmail.com> - 2012-07-11 21:32 -0400
Re: not understanding pattern matching Denis McMahon <denismfmcmahon@gmail.com> - 2012-07-13 03:22 +0000
Re: not understanding pattern matching Michael Joel <null@void.void> - 2012-07-11 19:11 -0400
Re: not understanding pattern matching Michael Joel <null@void.void> - 2012-07-11 23:27 -0400
| From | Michael Joel <null@void.void> |
|---|---|
| Date | 2012-07-11 18:35 -0400 |
| Subject | not understanding pattern matching |
| Message-ID | <vKadnRzba_frYmDSnZ2dnUVZ_qGdnZ2d@earthlink.com> |
I am wanting to change words in a string that has special tags. Ex. "This is a %/i%special%i% word in the string." If I want to replace any word between the %/i% and %i% what would I do? I messed with preg_repace but I couldn't understand the pattern system. Mike
[toc] | [next] | [standalone]
| From | Michael Fesser <netizen@gmx.de> |
|---|---|
| Date | 2012-07-12 00:49 +0200 |
| Message-ID | <2k0sv7dto2p429rl73r9n7hna7e06sh0jk@mfesser.de> |
| In reply to | #6536 |
.oO(Michael Joel) >I am wanting to change words in a string that has special tags. >Ex. "This is a %/i%special%i% word in the string." >If I want to replace any word between the %/i% and %i% what would I do? > >I messed with preg_repace but I couldn't understand the pattern system. What have you tried so far? Do you have any experiences with regular expressions? Micha -- http://mfesser.de/ Fotos | Blog | Flohmarkt
[toc] | [prev] | [next] | [standalone]
| From | Michael Joel <null@void.void> |
|---|---|
| Date | 2012-07-11 19:11 -0400 |
| Message-ID | <7didnTrFNO5ummPSnZ2dnUVZ_q-dnZ2d@earthlink.com> |
| In reply to | #6537 |
Michael Fesser wrote: > .oO(Michael Joel) > > >>I am wanting to change words in a string that has special tags. >>Ex. "This is a %/i%special%i% word in the string." >>If I want to replace any word between the %/i% and %i% what would I do? >> >>I messed with preg_repace but I couldn't understand the pattern system. > > > What have you tried so far? Do you have any experiences with regular > expressions? > > Micha > I have tried many things but all return errors - mostly "unknown modifier". Mike
[toc] | [prev] | [next] | [standalone]
| From | Michael Fesser <netizen@gmx.de> |
|---|---|
| Date | 2012-07-12 01:26 +0200 |
| Message-ID | <4p2sv71t7ak9hg1tk2jglnrvgl9ri7mpnc@mfesser.de> |
| In reply to | #6538 |
.oO(Michael Joel) >Michael Fesser wrote: > >> .oO(Michael Joel) >> >> >>>I am wanting to change words in a string that has special tags. >>>Ex. "This is a %/i%special%i% word in the string." >>>If I want to replace any word between the %/i% and %i% what would I do? >>> >>>I messed with preg_repace but I couldn't understand the pattern system. >> >> >> What have you tried so far? Do you have any experiences with regular >> expressions? >> >> Micha >> > >I have tried many things but all return errors - mostly "unknown modifier". Which means syntax error. Please post your code. Micha -- http://mfesser.de/ Fotos | Blog | Flohmarkt
[toc] | [prev] | [next] | [standalone]
| From | Michael Joel <null@void.void> |
|---|---|
| Date | 2012-07-11 19:31 -0400 |
| Message-ID | <V5KdnVyG6ph9kWPSnZ2dnUVZ_uWdnZ2d@earthlink.com> |
| In reply to | #6540 |
Michael Fesser wrote:
> .oO(Michael Joel)
>
>
>>Michael Fesser wrote:
>>
>>
>>>.oO(Michael Joel)
>>>
>>>
>>>
>>>>I am wanting to change words in a string that has special tags.
>>>>Ex. "This is a %/i%special%i% word in the string."
>>>>If I want to replace any word between the %/i% and %i% what would I do?
>>>>
>>>>I messed with preg_repace but I couldn't understand the pattern system.
>>>
>>>
>>>What have you tried so far? Do you have any experiences with regular
>>>expressions?
>>>
>>>Micha
>>>
>>
>>I have tried many things but all return errors - mostly "unknown modifier".
>
>
> Which means syntax error.
>
> Please post your code.
>
> Micha
>
I was trying to just first get it to replace the exact thing typed. Then
move on to replacing any word within the %/i% and %i%
$Scripture="this is a %/i%test%i%";
preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
This errors with Unknown modifier t
I tried what I thought was escaping it by putting a \test but that just
messes up more. See I haven't a clue.
Mike
[toc] | [prev] | [next] | [standalone]
| From | BootNic <bootnic.bounce@gmail.com> |
|---|---|
| Date | 2012-07-11 21:32 -0400 |
| Message-ID | <20120711213252.6c7021db@bootnic.server> |
| In reply to | #6541 |
[Multipart message — attachments visible in raw view] — view raw
In article <V5KdnVyG6ph9kWPSnZ2dnUVZ_uWdnZ2d@earthlink.com>,
Michael Joel <null@void.void> wrote:
> Michael Fesser wrote:
>>
>> .oO(Michael Joel)
>>>
>>> Michael Fesser wrote:
>>>>
>>>> .oO(Michael Joel)
>>>>>
>>>>> I am wanting to change words in a string that has special tags.
>>>>> Ex. "This is a %/i%special%i% word in the string."
>>>>> If I want to replace any word between the %/i% and %i% what would I do?
>>>>>
>>>>> I messed with preg_repace but I couldn't understand the pattern system.
>>>>
>>>> What have you tried so far? Do you have any experiences with regular
>>>> expressions?
>>>
>>> I have tried many things but all return errors - mostly "unknown modifier".
>>
>> Which means syntax error.
>>
>> Please post your code.
>
> I was trying to just first get it to replace the exact thing typed. Then
> move on to replacing any word within the %/i% and %i%
>
> $Scripture="this is a %/i%test%i%";
> preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
[url] http://php.net/manual/en/regexp.reference.delimiters.php [/url]
preg_replace("#%/i%test%i%#","XXXXXXXX",$Scripture);
> This errors with Unknown modifier t
> I tried what I thought was escaping it by putting a \test but that just
> messes up more. See I haven't a clue.
--
BootNic Wed Jul 11, 2012 09:32 pm
When I was young, I was put in a school for retarded kids for two years before
they realized I actually had a hearing loss...and they called ME slow!
*Kathy Buckley*
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2012-07-13 03:22 +0000 |
| Message-ID | <jto48v$sqg$1@dont-email.me> |
| In reply to | #6541 |
On Wed, 11 Jul 2012 19:31:12 -0400, Michael Joel wrote:
> I was trying to just first get it to replace the exact thing typed. Then
> move on to replacing any word within the %/i% and %i%
>
> $Scripture="this is a %/i%test%i%";
> preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
>
> This errors with Unknown modifier t I tried what I thought was escaping
> it by putting a \test but that just messes up more. See I haven't a
> clue.
http://php.net/manual/en/regexp.reference.delimiters.php
When you use a regex, the first character inside your quotes is taken as
the pattern delimiter.
In your case, this is a "%" character.
The format of a regex string is:
"delimiter pattern delimiter optional-modifiers"
Hence, "%/i%t" is the pattern "/i" with the modifier "t"
Try:
preg_replace("!%/i%test%i%!","XXXXXXXX",$Scripture);
This will use the "!" character as the pattern delimiter and should, in
this specific case, solve your problem. Generally it's a good idea to
pick a pattern delimiter that does not have special meaning to regex and
is not part of your data. This isn't always easy.
Rgds
Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Michael Joel <null@void.void> |
|---|---|
| Date | 2012-07-11 19:11 -0400 |
| Message-ID | <7didnTXFNO69lWPSnZ2dnUVZ_q8AAAAA@earthlink.com> |
| In reply to | #6537 |
Michael Fesser wrote: > .oO(Michael Joel) > > >>I am wanting to change words in a string that has special tags. >>Ex. "This is a %/i%special%i% word in the string." >>If I want to replace any word between the %/i% and %i% what would I do? >> >>I messed with preg_repace but I couldn't understand the pattern system. > > > What have you tried so far? Do you have any experiences with regular > expressions? > > Micha > answer to your last question - No
[toc] | [prev] | [next] | [standalone]
| From | Michael Joel <null@void.void> |
|---|---|
| Date | 2012-07-11 23:27 -0400 |
| Message-ID | <jeSdnYiZIMaQ2WPSnZ2dnUVZ_uSdnZ2d@earthlink.com> |
| In reply to | #6536 |
Michael Joel wrote: > I am wanting to change words in a string that has special tags. > Ex. "This is a %/i%special%i% word in the string." > If I want to replace any word between the %/i% and %i% what would I do? > > I messed with preg_repace but I couldn't understand the pattern system. > > Mike Since this function seems to elude me I simply wrote a samll function to do what I want. I simply pass it the two needles, haystack and what I want to replace with. Thanks Mike
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web