LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search and Replace String with Regex

Solved!
Go to solution

wiebe@CARYA wrote:

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.

I found a regexp that can capitalize words, but LV doesn't support \u ...

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 11 of 15
(273 Views)

@Yamaeda wrote:

wiebe@CARYA wrote:

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.

I found a regexp that can capitalize words, but LV doesn't support \u ...


PCRE and PCRE2 don't support the Perl \u escape sequence.

 

Spoiler

from PCRE2 documentation:

Unsupported escape sequences
In Perl, the sequences \F, \l, \L, \u, and \U are recognized by its string handler and used to modify the case of following characters. By default, PCRE2 does not support these escape sequences in patterns. However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX options is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above.

Message 12 of 15
(263 Views)

@Martin_Henz wrote:

@Yamaeda wrote:

wiebe@CARYA wrote:

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.

I found a regexp that can capitalize words, but LV doesn't support \u ...


PCRE and PCRE2 don't support the Perl \u escape sequence.

 

Spoiler

from PCRE2 documentation:

Unsupported escape sequences
In Perl, the sequences \F, \l, \L, \u, and \U are recognized by its string handler and used to modify the case of following characters. By default, PCRE2 does not support these escape sequences in patterns. However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX options is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above.



@Martin_Henz wrote:

@Yamaeda wrote:

wiebe@CARYA wrote:

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.

I found a regexp that can capitalize words, but LV doesn't support \u ...


PCRE and PCRE2 don't support the Perl \u escape sequence.

 

Spoiler

from PCRE2 documentation:

Unsupported escape sequences
In Perl, the sequences \F, \l, \L, \u, and \U are recognized by its string handler and used to modify the case of following characters. By default, PCRE2 does not support these escape sequences in patterns. However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX options is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above.


But I think \U sets case sensitivity.

 

That's not enabling replacing all a -> A, or 1 -> one.

An inlined function would be able to do that.

 

import re

def uppercase(match):
    text = match.group(1)
    return text.upper()

pattern = r"<b>(.*?)</b>"
text = "This is <b>bold</b> text."

result = re.sub(pattern, uppercase, text)
print(result)

 

0 Kudos
Message 13 of 15
(238 Views)

This example with uppercase/lowercase can be done entirely by PCRE2.

 

snip.png

Yes, of course, I still needed a few hours now, because my PCRE2 library was not yet ready to be able to demonstrate that and that package is still a few hours away from release.

Much more complicated changes are, however, not possible with PCRE2 alone.

 

Message 14 of 15
(206 Views)

wiebe@CARYA wrote:

@raphschru wrote:

wiebe@CARYA wrote:

@raphschru wrote:

I'd personally use a positive lookahead to have the replace string contain exactly what I want to insert:

Search and replace string with regex - positive lookahead.pngSearch and replace string with regex - positive lookahead - result.png


I never remember the syntax of those look arounds when I need them, so I don't use them unless I have to. They are quite powerful..


I often go to https://regex101.com/.

The Quick Reference section is wonderful for finding the syntax I need.


I have a copy of O'Reilly Python Pocket Reference (9781449357016). 2,- EU at a thrift shop.

It has 2 paragraphs that summarize everything about reg.ex.'s.

 

I don't use it for anything else (since it's about Python).

 

I do miss a few things Python can do, like calling custom functions from a reg.ex.. That would be very powerful, for things like capitalizing start of words, or incrementing numbers, etc.. These things require loops, cases and shift registers in LabVIEW. I suppose LabVIEW could do that by providing a (array of) (strong typed) VI server input... But the only way I see it happening is if we make it and show it off to NI.


OpenG libs have LabVIEW native functions for capitalizeing, etc... 

 

OpenG String Library Toolkit for LabVIEW - Download - VIPM by JKI

0 Kudos
Message 15 of 15
(186 Views)