1

I want from this text with CamelCase search words to generate. I do not know if that's possible only with RegEx. but I'm already close. I use it in the scripting language AutoHotkey (https://autohotkey.com/docs/misc/RegEx-QuickRef.htm) .

data: reCommended for future AutoHotkeyReleases.

regEx: (((\b[^A-Z\s]*)?([A-Z][a-z]+)|([\W_-]?[a-z]+))) ( https://regex101.com/r/NgRmXZ/2 )

expected Groups:

reCommended 
re
Commended 
for
future
Auto
Hotkey
AutoHotkey
HotkeyReleases
Releases
AutoHotkeyReleases.

i also tried, but not works for me:

(?=\p{Lu}\p{Ll})|(?<=\p{Ll})(?=\p{Lu}) from Splitting CamelCase with regex

(([a-z]*)(?<=[a-z])((?:[A-Z])[a-z]+)) https://regex101.com/r/NgRmXZ/3

(?<=[a-z])([A-Z])|(?<=[A-Z])([A-Z][a-z]) https://regex101.com/r/NgRmXZ/4

((?<!^)([A-Z][a-z]+|(?<=[a-z])[A-Z][a-z]+)) https://regex101.com/r/B5vXaZ/1

I have started to implement my prototyp already here: https://gist.github.com/sl5net/ba5aef19f44fe68204ccb6c96e7c96e0

SL5net
  • 2,282
  • 4
  • 28
  • 44

1 Answers1

1

I have made a regex that almost satisfies your need. However, I'm missing one combination. I don't think, it's possible, because it would require parantheses to overlap, the 'Hotkey' would have to be part of two different overlapping Groups.

Well, here's the regex:

/\b((\w+?(?=[A-Z]|\b))([A-Z][a-z]*)?)([A-Z][a-z]*)?/g

It starts by a Word boundary, then creates 2 Groups, Group 2 matches any Word character one or more times (ungreedy) until a look ahead for a Capital letter OR a Word boundary is reached.

Group 3 will match a Capital letter followed by zero or more lowercase letters. That is optional.

Group 1 combines Group 2 and Group 3.

Finally Group 4 will match a Capital letter followed by zero or more lowercase letters. That is optional.

As mentioned, I don't think its possible to create a Group, that combines Group 3 and Group 4, since they overlap. Other than that, this should Work, as you want.

Poul Bak
  • 10,450
  • 5
  • 32
  • 57
  • 1
    it works also in autohotkey specific regEx. i implemeted it here: https://github.com/sl5net/global-IntelliSense-everywhere-Nightly-Build/blob/master/Source/tests/test_getAutoKeywords.ahk – SL5net Nov 18 '18 at 10:09