Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular expression help
#1
The following macro is used for removing <...> code characters form a string :

Function tempf02
Code:
Copy      Help
str s=
;<>  1.  91.  9. 11  02-02-2015  <c 8388608>TAM                         24.08</c>
;;;2.   5. 91.  1  04-02-2015  <c 0>LOG          50.00               </c>
;;;3.   5. 92.  1  06-02-2015 <c 0>LOG        20.00               </c>
;;;4.   1. 11.  2  09-02-2015 <c 0>LOG                     1,050.07</c>


s.findreplace("<>" "")
s.replacerx("<.*>" "")

out s

My question is : Is it possible to combine the findreplace and replacerx statements into one replacerx? I tried, but I failed, as it happens usually with regular expressions.

Any help will be much appreciated.
#2
Do you want the output like this?

1. 91. 9. 11 02-02-2015 TAM 24.08
2. 5. 91. 1 04-02-2015 LOG 50.00
3. 5. 92. 1 06-02-2015 LOG 20.00
4. 1. 11. 2 09-02-2015 LOG 1,050.07

s.replacerx("^\<*\>$" "")

or this

1. 91. 9. 11 02-02-2015
2. 5. 91. 1 04-02-2015
3. 5. 92. 1 06-02-2015
4. 1. 11. 2 09-02-2015
#3
Thank you very much, indeed. I need the first option. I tried the expression you suggested, it worked for all the lines, except the first, with <c 8388608>.

Best regards !
#4
Function tempf02a
Code:
Copy      Help
str s=
;<> 1. 91. 9. 11 02-02-2015 <c 8388608>TAM 24.08</c>
;;;2. 5. 91. 1 04-02-2015 <c 0>LOG 50.00 </c>
;;;3. 5. 92. 1 06-02-2015 <c 0>LOG 20.00 </c>
;;;4. 1. 11. 2 09-02-2015 <c 0>LOG 1,050.07</c>


s.replacerx("^\<.*\>$" "")
out s

tbis worked for me for all lines

output
1. 91. 9. 11 02-02-2015 TAM 24.08
2. 5. 91. 1 04-02-2015 LOG 50.00
3. 5. 92. 1 06-02-2015 LOG 20.00
4. 1. 11. 2 09-02-2015 LOG 1,050.07

as did this
s.replacerx("^\<*\>$" "")
so i'm not sure what is going on.
#5
try this also
s.replacerx("\<\>|\<(.+?)\>" "")

Code:
Copy      Help
str s=
;<> 1. 91. 9. 11<abc> 02-02-2015 <c 8388608>TAM 24.08</c>
;;;2. 5. 91.<This is a full sentence.> 1 04-02-2015 <c 0>LOG 50.00 </c>
;;;3. 5. 92. 1 06-02-2015 <c 0>LOG 20.00 </c>
;;;4.<hij> 1. 11. 2 09-02-2015 <c 0>LOG 1,050.07</c><k><l><>


s.replacerx("\<\>|\<(.+?)\>" "")
out s


output
1. 91. 9. 11 02-02-2015 TAM 24.08
2. 5. 91. 1 04-02-2015 LOG 50.00
3. 5. 92. 1 06-02-2015 LOG 20.00
4. 1. 11. 2 09-02-2015 LOG 1,050.07
#6
This is perfect! Many thanks Indeed.


Forum Jump:


Users browsing this thread: 1 Guest(s)