Regular expression to match a word or its prefix

Square brackets are meant for character class, and you’re actually trying to match any one of: s, |, s (again), e, a, s (again), o and n. Use parentheses instead for grouping: or non-capturing group: Note: Non-capture groups tell the engine that it doesn’t need to store the match, while the other one (capturing group does). For small stuff, either works, for ‘heavy duty’ stuff, you … Read more

Regex Match all characters between two strings

For example Regexr I used lookbehind (?<=) and look ahead (?=) so that “This is” and “sentence” is not included in the match, but this is up to your use case, you can also simply write This is(.*)sentence. The important thing here is that you activate the “dotall” mode of your regex engine, so that … Read more

RE error: illegal byte sequence on Mac OS X

A sample command that exhibits the symptom: sed ‘s/./@/’ <<<$’\xfc’ fails, because byte 0xfc is not a valid UTF-8 char.Note that, by contrast, GNU sed (Linux, but also installable on macOS) simply passes the invalid byte through, without reporting an error. Using the formerly accepted answer is an option if you don’t mind losing support for your true locale (if you’re on a US system … Read more

Finding the complement of a DFA?

As you says in question: I know that to convert a DFA, M to the complement, M`, I just need to swap the initial accepting states and final accepting states. Its not complement, but you are doing something like reverse of a language and regular languages are closure under reversal. Reversal of DFA What is the Reversal Language ? … Read more

Regex optional capturing group?

The reason that you do not get an optional cat after a reluctantly-qualified .+? is that it is both optional and non-anchored: the engine is not forced to make that match, because it can legally treat the cat as the “tail” of the .+? sequence. If you anchor the cat at the end of the … Read more

Regex to match only letters

Use a character set: [a-zA-Z] matches one letter from A–Z in lowercase and uppercase. [a-zA-Z]+ matches one or more letters and ^[a-zA-Z]+$ matches only strings that consist of one or more letters only (^ and $ mark the begin and end of a string respectively). If you want to match other letters than A–Z, you can either add them to the character set: [a-zA-ZäöüßÄÖÜ]. Or … Read more

Regex to match only uppercase “words” with some exceptions

To some extent, this is going to vary by the “flavour” of RegEx you’re using. The following is based on .NET RegEx, which uses \b for word boundaries. In the last example, it also uses negative lookaround (?<!) and (?!) as well as non-capturing parentheses (?:) Basically, though, if the terms always contain at least one uppercase letter followed by at least … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)