Hi all, Regexp hasNewLines = regexp = "([^\n]*)[\n](.*)$" // I'm using XX instead of the HTML tag here string htmlBR = "XX" string fix (string original) { string fixed = original while (hasNewLines fixed) { fixed = fixed[match 1] htmlBR fixed[match 2] } return fixed }
s = fix("AAA\nBBB\nCCC")
SystemAdmin - Wed Aug 26 14:11:24 EDT 2009 |
Re: Replacing newline characters with other text with regexp
Here is a simpler way for those who don't know RE; may take longer than RE depending on task. //DemoReplace /*Replace newline with <br>*/ Buffer b=create string s="line 1\nline 2\nline 3" int j,l=length s for(j=0;j<l;j++) { if(s[j]=='\n') b+="<br>" else b+=s[j]"" } print b "" |
Re: Replacing newline characters with other text with regexp
Pretty much straight from the DXL Reference Manual. Regexp newLine = regexp(".*"); string htmlBR = "<br>"; string fix (string original) { string fixed = "" while(!null(original) && newLine original) { fixed = fixed original[match 0] htmlBR original = original[end 0 + 2:]; } return fixed } print fix("AAA\nBBB\nCCC")
|
Re: Replacing newline characters with other text with regexp dpechacek - Thu Aug 27 10:00:06 EDT 2009
Pretty much straight from the DXL Reference Manual. Regexp newLine = regexp(".*"); string htmlBR = "<br>"; string fix (string original) { string fixed = "" while(!null(original) && newLine original) { fixed = fixed original[match 0] htmlBR original = original[end 0 + 2:]; } return fixed } print fix("AAA\nBBB\nCCC")
AAI Services, Textron dpechacek@aai.textron.com David.Pechacek@gmail.com |
Re: Replacing newline characters with other text with regexp dpechacek - Thu Aug 27 10:00:06 EDT 2009
Pretty much straight from the DXL Reference Manual. Regexp newLine = regexp(".*"); string htmlBR = "<br>"; string fix (string original) { string fixed = "" while(!null(original) && newLine original) { fixed = fixed original[match 0] htmlBR original = original[end 0 + 2:]; } return fixed } print fix("AAA\nBBB\nCCC")
at end of line even thought end of line is not a newline character. |
Re: Replacing newline characters with other text with regexp Ron_Lewis - Thu Aug 27 11:48:49 EDT 2009 woops the forum messed up previous message
|
Re: Replacing newline characters with other text with regexp dpechacek - Thu Aug 27 10:00:06 EDT 2009
Pretty much straight from the DXL Reference Manual. Regexp newLine = regexp(".*"); string htmlBR = "<br>"; string fix (string original) { string fixed = "" while(!null(original) && newLine original) { fixed = fixed original[match 0] htmlBR original = original[end 0 + 2:]; } return fixed } print fix("AAA\nBBB\nCCC")
Thanks |
Re: Replacing newline characters with other text with regexp Add this statement in your while loop before you update 'fixed'. print "\t[" fixed[match 0] "] [" fixed[match 1] "] [" fixed[match 2] "] [" fixed[match 3] "]\n"
(.|\n)* // that's "Any character except new line, or new line" any number of times
Regexp hasNewLines = regexp "([^\n]*)[\n]((.|\n)*)$"
|
Re: Replacing newline characters with other text with regexp llandale - Thu Aug 27 15:51:15 EDT 2009 Add this statement in your while loop before you update 'fixed'. print "\t[" fixed[match 0] "] [" fixed[match 1] "] [" fixed[match 2] "] [" fixed[match 3] "]\n"
(.|\n)* // that's "Any character except new line, or new line" any number of times
Regexp hasNewLines = regexp "([^\n]*)[\n]((.|\n)*)$"
Thanks (This is an excellent forum - quick and accurate response and only a subtle "RTFM"!) |
Re: Replacing newline characters with other text with regexp SystemAdmin - Thu Aug 27 17:24:18 EDT 2009 |
Re: Replacing newline characters with other text with regexp llandale - Fri Aug 28 09:23:39 EDT 2009 I would much rather run though a tutorial and learn the language that way than make a fool of myself in these forums, I just have not been able to find one. OReilly does not have one, neither does Amazon, searches for DXL turn up a wide variety of results. I've learned quite a bit from the examples, however, some of them demonstrate only the syntax, and not all the nuances. Is there a tutorial out there, or do I learn this "by the seat of my pants"? I again thank everyone for their help, knowing that they are at least as busy as I am. |
Re: Replacing newline characters with other text with regexp SystemAdmin - Fri Aug 28 11:12:16 EDT 2009 https://www-304.ibm.com/jct03001c/services/learning/ites.wss/us/en?pageType=course_description&courseCode=QN116 |
Re: Replacing newline characters with other text with regexp SystemAdmin - Fri Aug 28 11:12:16 EDT 2009 Looking at examples is very useful. Make sure you understand each one, often going to the manual to figure out exactly what each statement is doing. Start by grasping all the snippettes you see on this forum, and advance to more complicated scripts. Modify some script to make them work a little differently. When you are reasonably comfortable understanding how the manual describes functions, then read the manual front to back. For example: ... bool f1(int Type, int f2(string)) ... means that perm f1 return boolean, and accepts two parameters, first it type int and second is a function that returns type int and requires a string parameter. You probably won't get a bunch of nuances in a tutorial anyway, such as you do NOT use the "&" charcter for array function parameters; otherwise DXL goes into never-never land when you modify the array. Don't do this: void SortArray(string &sArray[]) You won't find tutorials telling you which assignment statements assign the value and which ones define aliases. That's strange, since that's a pretty basic operation and should be in the manual. ... History h2 = h1 // Alias ... Buffer b2 = b1 // Alias ... Module m2 = m1 // Value ... etc
|
Re: Replacing newline characters with other text with regexp SystemAdmin - Fri Aug 28 11:12:16 EDT 2009 Ken. |
Re: Replacing newline characters with other text with regexp SystemAdmin - Fri Aug 28 11:12:16 EDT 2009 http://easyweb.easynet.co.uk/~iany/consultancy/papers_welcome.htm#DOORSDXL |
Re: Replacing newline characters with other text with regexp SystemAdmin - Fri Aug 28 13:30:05 EDT 2009 ". Let's say I wanted to replace "\n\n" with a "\n". In other words, I want to remove an empty line. I found this incredibly hard to do with DXL Regex implementation as it can only do one line at a time. I found a workaround for my issue--but wasn't satisfied that I couldn't figure it out in DXL. Any takers to this challenge? |
Re: Replacing newline characters with other text with regexp kbmurphy - Tue Jun 15 11:32:03 EDT 2010
I throw the replace() implementation of the DXL standard library in the ring! It is reasonably fast for short strings (<5000 chars). Regards, Mathias /*! \return Returns sSource, where the searchstring \em sSearch is replaced by sReplace \param sSource the source string in which \em sSearch shall be replaced \param sSearch the search string that shall be replaced \param sReplace the string by which \em sSearch shall be replaced \brief Replaces a part of the string by another string */ string replace (string sSource, string sSearch, string sReplace) { int iLen = length sSource if (iLen == 0) return "" int iLenSearch = length(sSearch) if (iLenSearch == 0) { raiseError ("Parameter error", "in strings.inc/replace: search string must not be empty") return "" } // read the first char for latter comparison -> speed optimization char firstChar = sSearch[0] Buffer s = create() int pos = 0, d1,d2; int i while (pos < iLen) { char ch = sSource[pos]; bool found = true if (ch != firstChar) {pos ++; s+= ch; continue} for (i = 1; i < iLenSearch; i++) if (sSource[pos+i] != sSearch[i]) { found = false; break } if (!found) {pos++; s+= ch; continue} s += sReplace pos += iLenSearch } string result = stringOf s delete s return result }
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Replacing newline characters with other text with regexp If you print your match 2 you'll see it does not include any C characters. That's because the period does not include any new lines (read that regexp table in the manual carefully). Combine that with the fact that the dollar sign means 'end of string or end of line', then any 3rd line doesn't get included. I could not make this work. Like I said I'm real clumsy with Regular expressions, but looking back through my cob-webs of code I see these two interesting things: [1] "()" [2] "( Both are supposed to have the meaning "any number of any characters including EOL" in a regular expression; but frankly I don't remember what the deal is.
|
Re: Replacing newline characters with other text with regexp llandale - Tue Jun 15 20:19:54 EDT 2010
Hello Team, I have a string as below in blue and I want to split into three parts like
Input
Internal Data 1. I should check for the string should start with Input 2. I need first 3 lines into one string
Input 3. From 4th line till the Internal Data I need separately like
HCM1_hcmone1000msec_good 4. From Internal Data to None into separate string
Internal Data 5, After internal data if anystring apart from None then I want that to be separate string
Please help me Basically my task is to make bold for the text from 4th line until internal data and after internal data if any data then I should make bold for that also and the rest as normal text as shown below Ex: 1
Input
Internal Data Ex:2
Input
Internal Data Kindly help me how to do this in dxl
Regards, Shrunavi |
Re: Replacing newline characters with other text with regexp shrunavi - Mon Aug 14 02:49:13 EDT 2017 Hello Team, I have a string as below in blue and I want to split into three parts like
Input
Internal Data 1. I should check for the string should start with Input 2. I need first 3 lines into one string
Input 3. From 4th line till the Internal Data I need separately like
HCM1_hcmone1000msec_good 4. From Internal Data to None into separate string
Internal Data 5, After internal data if anystring apart from None then I want that to be separate string
Please help me Basically my task is to make bold for the text from 4th line until internal data and after internal data if any data then I should make bold for that also and the rest as normal text as shown below Ex: 1
Input
Internal Data Ex:2
Input
Internal Data Kindly help me how to do this in dxl
Regards, Shrunavi Search the forum for regexp examples and do not pull such old posts! Instead open a new post. Use a minimal example. Try to come up with some code on your own and ask specific questions instead of "Please code this for me" questions. Regards, Mathias |