Question

I'm wondering if it's possible to create a regular expression that will output a fixed string like 'bla' as group #1 regardless of the input string?

I'm using a library method to get the username from a string via a regex match. The used regex is the only variable I can give to that method, the input string is always the same and in this particular situation does not contain the needed output string.

Was it helpful?

Solution

For the record, some time ago I happened to ask Jan Goyvaerts, who is the author of RegexBuddy and knowledgeable about a myriad regex flavors, whether he happened to know a regex flavor that allows inserting arbitrary text in the replacement—not as a callback or lambda. For instance, a conditional allowing you to insert foo when Group 1 is matched. Or a trick to capture text that isn't there, perhaps with some kind of weird lookaround-fu. He replied that he does not know any flavor allowing this. I believe this is what you were looking for.

I'm sure you're aware that programming languages allow you to manipulate your replacement text in anonymous functions and callbacks... But that's doesn't seem to be what you were after.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top