Jump to content


Photo

REPLACE_TEXTUALLY with word sensitive regexp?


  • Please log in to reply
7 replies to this topic

#1 Ulb

Ulb
  • Modder
  • 373 posts

Posted 08 January 2018 - 04:41 PM

I just don't understand regexp it seems. Could anyone point out why this isn't working?

 

 

ALTER_TLK BEGIN
REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH  ~\bDorn\b~ ~Dorna~
END

WeiDU doesn't complain but nothing gets changed during the install. If I try it without \b it will replace all instances of "dorn" so Keldorn becomes KelDorna and so forth. I can avoid that by going case_sensitive but I would much rather use word sensitive replacement to avoid any unforseen issues.

 

Also, if anyone knows a good tutorial on regexp syntax  I'd be grateful for a link. The WeiDU readme doesn't really give any examples for regexp.

 



#2 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 08 January 2018 - 06:55 PM

The problem is likely EXACT_MATCH, which is going to be looking for \b exactly. You don't want that, and for that matter, using CASE_SENSITIVE instead of CASE_INSENSITIVE will avoid matching "dorn" in "Keldorn." With the word boundary, it won't match possessives either (e.g. Dorn's).

 

So you might just try:

REPLACE_TEXTUALLY CASE_SENSITIVE ~Dorn~ ~Dorna~

If there's any words that begin with a capital "Dorn" you don't want to change, you can tweak it accordingly.


Edited by Miloch, 08 January 2018 - 07:07 PM.

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#3 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 08 January 2018 - 08:16 PM

Hmm, now sure if it actually works as I expect it to, but what about ~\([^A-Za-z]?\)Dorn\([^A-Za-z]?\)~ ~\1Dorna\2~?


Retired from modding.


#4 Ulb

Ulb
  • Modder
  • 373 posts

Posted 08 January 2018 - 08:26 PM

Thanks, both of you.

 

You don't want that, and for that matter, using CASE_SENSITIVE instead of CASE_INSENSITIVE will avoid matching "dorn" in "Keldorn." With the word boundary, it won't match possessives either (e.g. Dorn's).

 

That is actually a really good point I hadnt thought about, makes using case_sensitive ~Dorn~ ~Dorna~ more appealing.

Still, I will likely have to replace quite a few more .tlk entries so I would like to understand what I'm doing wrong and how to properly use regexp.

 

*edit* to expand on that; If I can use word sensitive replacement I can make sure I don't change something else, like Bob Dornwood becoming Bob Dornawood. I'll just have to make sure to also take care of posessives...

With just relying on case_sensitive there is always a chance to accidentially change something else.

 

 

Hmm, now sure if it actually works as I expect it to, but what about ~\([^A-Za-z]?\)Dorn\([^A-Za-z]?\)~ ~\1Dorna\2~?

 

Same result. No WeiDU complains but no actual string changes either...

(Also, just when I thought maybe it's not that complicated after all you post this abomination...)

 

Bottom line; am I to understand that

 

~\bDorn\b~ ~Dorna~

 

should in theory be properly phrased?


Edited by Ulb, 08 January 2018 - 08:31 PM.


#5 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 08 January 2018 - 10:56 PM

Just tried it, and it works fine:

OUTER_PATCH_SAVE x ~Dorn's name is Keldorn Dornwood. KELDorn DORN Dorn.~ BEGIN
  REPLACE_TEXTUALLY CASE_SENSITIVE ~\bDorn\b~ ~Dorna~
END
PRINT ~%x%~

 


Retired from modding.


#6 Ulb

Ulb
  • Modder
  • 373 posts

Posted 09 January 2018 - 05:21 AM

Just tried it, and it works fine:

OUTER_PATCH_SAVE x ~Dorn's name is Keldorn Dornwood. KELDorn DORN Dorn.~ BEGIN
  REPLACE_TEXTUALLY CASE_SENSITIVE ~\bDorn\b~ ~Dorna~
END
PRINT ~%x%~

 

 

It actually does.

So Miloch was right in the beginning when he said EXACT_MATCH was the issue.

Strange that EXACT_MATCH seems to make WeiDU ignore regexp syntax.

 

Anyway, problem solved, thanks again!



#7 Mike1072

Mike1072
  • Modder
  • 539 posts

Posted 09 January 2018 - 08:37 PM

Strange that EXACT_MATCH seems to make WeiDU ignore regexp syntax.

That's the entire purpose of EXACT_MATCH. It's for when you don't want regexp matches.

#8 Ulb

Ulb
  • Modder
  • 373 posts

Posted 10 January 2018 - 05:31 AM

Yeah, it dawned on me that this might be the case :crazy: