Replaces the specified "(" with a newline character and removes all non-Chinese and non-numeric characters.
d试1(-是23(a文字789(+内c容4$3
txt="d试1(-是23(a文字789(+内c容4$3"; na=Regex(txt, ?? );
Thanks!
use two statements. I added some extra problem characters to your example...
txt = "d试1(-是2^3([a]文/字789(+内\c容4$3"; step1 = Regex( txt, "\(", "\!n", globalreplace ); step2 = Regex( step1, "[-+/\\^$[\]a-zA-Z]", "", globalreplace );
</CODE>The ( needs to be regex-escaped for step1. The newline is JSL-escaped.</P> <P><CODE class=" language-jsl">For step2, the syntax of the [...] is complicated:
</CODE>The ( needs to be regex-escaped for step1. The newline is JSL-escaped.</P> <P><CODE class=" language-jsl">
Be careful not to accidentally write the JSL-escape \[ which changes the way JSL interprets strings. This is likely to happen when working with character sets in [...] if you don't know it will be a problem.
Notice the sequence [\]. It is not a character set. It is 2 characters that are in a character set.
Thank Craige!
I'll just use EmEditor to re replace
If I want to take this re substitution one step further: insert tabs between the Chinese characters and the data (set the Chinese characters in the original text to the left and the numbers to the right), to achieve a table that can input the result of the substitution directly into the JMP:How do you need to change the code?
txt = "d试1(-是2^3([a]文/字789(+内\c容4$3"; step1 = Regex( txt, "\(", "\!n", globalreplace );//?? step2 = Regex( step1, "[-+/\\^$[\]a-zA-Z]", "", globalreplace );//?? s = N Items( step2 ); dt = New Table( "A", Add Rows( s ), New Column( "txt", Character, "Nominal" ), New Column( "num" ) ); dt[0, 0] = step2;
This is an example for negative look behind and positive look ahead, lookaround. Step 3 is using both.
(?<!\d)
matches a single character that is not a digit just before the current zero-length position.
(?=\d)
matches a single character that is a digit just after the current zero-length position.
The tab character is inserted into the zero-length position to separate the non-digit from the digit.
txt = "d试1(-是2^3([a]文/字789(+内\c容4$3"; // change paren to newline... step1 = Regex( txt, "\(", "\!n", globalreplace ); // remove unwanted characters - + / \ ^ $ [ ] a..z A..Z step2 = Regex( step1, "[-+/\\^$[\]a-zA-Z]", "", globalreplace ); // insert tab when character before is not a digit and character after is a digit step3 = Regex( step2, "(?<!\d)(?=\d)", "\!t", globalreplace ); // add header step4 = "aaa\!tbbb\!n" || step3; // import the string without making a file on disk Open( Char To Blob( step4 ), "text" );
tabs separate fields
Look at the code you write, a real enjoyment!