Greg_L_WER
asked on
Regex - Ignoring Spaces
Good morning... I'm fairly new to regular expressions and am trying to edit code that another developer built to accommodate some new text. The way that the text is being saved in our new process is removing some of the spaces for some reason so I'm now needing to modify the Regex's to accommodate this change. In the OLD Regex there are spaces in the statement where the spaces exist in the string... running this Regex on the new string returns nothing. I updated the Regex to remove the spaces and it does work though I need this code to run against old and new strings. I'm hoping that there is a way to modify the expression to work in both situations. Any help would be appreciated. Please let me know if you need additional clarification.
Thanks,
Greg
Thanks,
Greg
[b]CURRENT CODE[/b] - Note the space after Number:_ and after the number 440_
String being used "....Corporate Access Number: 201093440 \r\nLegal Entity Name...."
Regex canRegex = new Regex(@"Corporate Access Number: (?<desc>.+?) \r\nLegal Entity Name", RegexOptions.IgnoreCase, timeOut);
[b]NEW CODE[/b] - In the new version of the text the output removes the spaces in both places
String being used "....Corporate Access Number:201100146\r\nLegal Entity Name...."
Regex canRegex = new Regex(@"Corporate Access Number:(?<desc>.+?)\r\nLegal Entity Name", RegexOptions.IgnoreCase, timeOut);
Can you use this RegEx?
Regex canRegex = new Regex(@"Corporate Access Number: \d+( )*[\n\r]+Legal Entity Name....", RegexOptions.IgnoreCase, timeOut);
@Shawn: I thing the OPs code uses the "desc" group somewhere.
Yup OP might, but thought worthwhile to post because OP also said another developer built it and requirements might have changed
ASKER
Thanks everyone...
Dan Craciun - I tried your suggestion and it did return a value but was missing some data. I edited it slightly by using \s* in place of any spaces and it seems to be working in both cases. Can you foresee any issues that this could cause or would this work in all situations?
Thanks,
Greg
Dan Craciun - I tried your suggestion and it did return a value but was missing some data. I edited it slightly by using \s* in place of any spaces and it seems to be working in both cases. Can you foresee any issues that this could cause or would this work in all situations?
Thanks,
Greg
Regex canRegex = new Regex(@"Corporate Access Number:\s*(?<desc>.+?)\s*\r\nLegal Entity Name", RegexOptions.IgnoreCase, timeOut);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Dan... could very well be another character... in debug it just appears to be a space. Thanks for help and confirming that it will meet my needs.
Open in new window
HTH,Dan