Regex How to remove output result that you don want

Hi I have this regex here: (?<=Module Name:\s)((^|)([A-Z] (#|++)?\s|[A-Z] (-)?|(/|,)|[0-9]{1}|\s\w))+(?<=Module Code)

I don want the module code behind!! All word document have this “Module Code” at the next line which will be read in for all my result, how do I not take in the module code words?

Once you have you string in a string variable, you can just use String.Replace() method to replace ‘Module Code’ with an empty string.

Like this,
str = str.Replace(“Module Code”,"")

Thanks,
Rammohan B.

@Jovian_Low I think this is because of the fact that you’ve used a positive lookbehind at the end of your regex instead of a positive lookahead. At the end of your regex, remove the ‘<’ in THIS (?<=Module Code) and then re-run your workflow.

Let me know if it resolved your problem.

@siddharth hey bro thank you once again it solved my problem! May I ask what is the difference between ?<= and just ?= :slight_smile:

@Jovian_Low the first one is something called a lookbehind while the latter is a lookahead expression.
Lookbehind looks BEHIND or BEFORE and matches only whatever you write AFTER that expression, excluding the pattern inside the expression.

Example: (?<=Module Name) Mechanics

This searches for the string “Module Name” but doesn’t include it in your matched string. So it includes ALL the “Mechanics” strings which have a “Module Name” BEHIND them.

Anyway, I suggest you read about lookbehinds and lookaheads, and Regex in general.

@siddharth okay thanks I will go look up on them :smile: