RegExp problem

RegExp problem

offline
  • Peca  Male
  • Glavni Administrator
  • Predrag Damnjanović
  • SysAdmin i programer
  • Pridružio: 17 Apr 2003
  • Poruke: 23209
  • Gde živiš: Niš

Imam string
"win98 i win 98 i windows"

treba mi regexp koji ce da nadje 'win' ako u nastavku nije 'dows'
znaci, da nadje 'win98' i 'win 98', ali ne i 'windows'

jedino sto sam uspeo je
Win[^d]

Mogu da negiram jedno slovo (d), ali nikako da uspem da negiram string ("dows") Sad

Neko resenje?

p.s. nemojte samo da mi dajete perl regexp, posto bih voleo iskljucivo regexp...



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • mire  Male
  • Elitni građanin
  • Pridružio: 18 Apr 2003
  • Poruke: 2282
  • Gde živiš: Beograd

evo ti dole perlregexp Wink

najbolje da mi poshaljesh skript pa cu da ti napishem kod

"(?=pattern)"
A zero-width positive look-ahead assertion. For example, "/\w+(?=\t)/" matches a word followed by a
tab, without including the tab in $&.

"(?!pattern)"
A zero-width negative look-ahead assertion. For example "/foo(?!bar)/" matches any occurrence of "foo"
that isn't followed by "bar". Note however that look-ahead and look-behind are NOT the same thing.
You cannot use this for look-behind.

If you are looking for a "bar" that isn't preceded by a "foo", "/(?!foo)bar/" will not do what you
want. That's because the "(?!foo)" is just saying that the next thing cannot be "foo"--and it's not,
it's a "bar", so "foobar" will match. You would have to do something like "/(?!foo)...bar/" for that.
We say "like" because there's the case of your "bar" not having three characters before it. You could
cover that this way: "/(?Sad?!foo)...|^.{0,2})bar/". Sometimes it's still easier just to say:

if (/bar/ && $` !~ /foo$/)



offline
  • Peca  Male
  • Glavni Administrator
  • Predrag Damnjanović
  • SysAdmin i programer
  • Pridružio: 17 Apr 2003
  • Poruke: 23209
  • Gde živiš: Niš

a ima li sanse da to bude regexp, a ne perlregexp ?

offline
  • mire  Male
  • Elitni građanin
  • Pridružio: 18 Apr 2003
  • Poruke: 2282
  • Gde živiš: Beograd

kazem ti, daj mi kod da vidim sta se tu radi Wink

mrzi me da se ovako cimam

offline
  • Peca  Male
  • Glavni Administrator
  • Predrag Damnjanović
  • SysAdmin i programer
  • Pridružio: 17 Apr 2003
  • Poruke: 23209
  • Gde živiš: Niš

pa kakav kod pobogu, nema tu koda, to je jedna linija, treba samo regexp da se formulise.

<?
$agent=eregi_replace ("win([^d])", "windows\\1", $agent);
?>

treba mi regexp koji ce da nadje 'win' ako u nastavku nije 'dows'
znaci, da nadje 'win98' i 'win 98', ali ne i 'windows'

i po mogucstvu da ne bude perl regexp Smile

offline
  • mire  Male
  • Elitni građanin
  • Pridružio: 18 Apr 2003
  • Poruke: 2282
  • Gde živiš: Beograd

evo ovako bez provere

if (!preg_match('/windows/', $agent)):
$agent=eregi_replace ("win\s?(\d+)", "windows\\1", $agent);
endif;

btw ako ti ne bude radi ereg_replace samo uradi verziju sa preg_replace

\s? matchuje jedan ili nijedan space

a u zagradi hvatash jedan ili vishe brojeva

Ko je trenutno na forumu
 

Ukupno su 650 korisnika na forumu :: 31 registrovanih, 4 sakrivenih i 615 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: -[CoA]-, 8u47, alkatraz080, Andrija357, Atomski čoban, bigfoot, brundo65, comi_pfc, darkangel, Hektor, hyla, ILGromovnik, JOntra, Kriglord, kybonacci, mercedesamg, MilosKop, opt1, Outis, Parker, procesor, Recce, S2M, Shinobi, Smd, Sterilizacija, uruk, Vatrogasaccc, VladaNS1978, zhuki8, 187