Asked by:
Matching an Entire Line of String Without Knowing Where Line Break Will Be

Question
-
User1231829591 posted
Currently I am using the following REGEX pattern to match an entire line of string:
^my input string$
The above pattern works if my input string is short and there is no word wrap, new line, line break, carriage return etc. The problem is I don't know where the word will wrap or where the line break will be ahead of time.
Sunday, April 26, 2020 6:01 AM
All replies
-
User-18289217 posted
what is the end of the line in the given context? Dot? Something else?
Sunday, April 26, 2020 11:35 AM -
User288213138 posted
Hi ManyTitles,
The above pattern works if my input string is short and there is no word wrap, new line, line break, carriage return etc. The problem is I don't know where the word will wrap or where the line break will be ahead of time.According to your description, I couldn’t understand your requirement clearly.
Do you mean you want to match all sting with line break?
If this is your requirement, I suggest you could try this regular expression:
([\d\D]*)
The result:
If I misunderstand your requirement, please post more details information about your requirement.
Best regards,
Sam
Monday, April 27, 2020 3:35 AM -
User1231829591 posted
The end of the line could be any string. For example let's say the string I'm trying to match consists of 50 words. When the screen is narrower than the space required for 50 words the string will wrap and show up on the next line.
The point at which the wrap happens cannot be determined in advance, but I want to create a pattern that matches the entire string even if that string wraps for any reason. Some times people will use a new line character, a carriage return, etc. to cause the string to wrap so that the string will fit on the page.
Monday, April 27, 2020 10:12 PM -
User303363814 posted
Replace line breaks with spaces before you do the matching
Monday, April 27, 2020 10:37 PM -
User1231829591 posted
Hi Sam,
Thanks for your reply. Unfortunately the pattern you used above will match any string that satisfies that pattern not just the string I want. Let me give you a little backgound on what I'm trying to achieve. Suppose I have a text document that is displayed on the screen and I want to be able to replace text displayed in that document. I want to be able to copy a string on that screen and create a REGEX pattern that will match the copied string then it will be replaced by another string.
It is not straight forward because there could be line breaks in the copied string caused by all sorts of different things. For instance a line break could be caused by the use of a new line character, by a carriage return character, or simply by turning on Word Wrap which would wrap a string if it's longer than the screen width. The point is I would like to make sure the pattern matches the string word for word and also make sure it matches special characters (that cause the line to break) if they exist.
Monday, April 27, 2020 10:39 PM -
User288213138 posted
Hi many Titles,
Thanks for your reply. Unfortunately the pattern you used above will match any string that satisfies that pattern not just the string I want. Let me give you a little backgound on what I'm trying to achieve. Suppose I have a text document that is displayed on the screen and I want to be able to replace text displayed in that document. I want to be able to copy a string on that screen and create a REGEX pattern that will match the copied string then it will be replaced by another string.
It is not straight forward because there could be line breaks in the copied string caused by all sorts of different things. For instance a line break could be caused by the use of a new line character, by a carriage return character, or simply by turning on Word Wrap which would wrap a string if it's longer than the screen width. The point is I would like to make sure the pattern matches the string word for word and also make sure it matches special characters (that cause the line to break) if they exist.
This seems impossibleIf, you want to use regular to match exactly. Because you don’t know when the line break appears.
You can try to use C # code for this string, and then use regular expressions.
Best regards,
Sam
Thursday, April 30, 2020 6:45 AM