String Pipes, using regexp and 'check the official documentation.'
Closed this issue · 0 comments
Thanks for all the awesome work creating this capability
some tips for use, didn't see in docs,
-In the help docs, where 'check the official documentation.' is referenced, this is referring to the official javascript documentation, the functions being used are standard javascript functions
-these functions still need to be translated into compatible pipe syntax
e.g. Javascript string.replace example: res = str.replace("AAA", "B") // res 'BAA'
Pipe equivalent = {{'AAA' | replace: 'A' : 'B'}} // returns 'BAA'
To use Regular Expressions you can't pass as strings, so if you want to do a global replace, this won't work:
{{'AAA' | replace: '/A/g' : 'B'}} // AAA (regex is treated as a string, no match found)
nor will this
{{'AAA' | replace: /A/g : 'B'}} // (generates console error)
Instead, create a typescript regexp variable in the associated component.ts:
public myRegex = new RegExp(/A/g);
Then use this in the pipe
{{'AAA' | replace: myRegex : 'B'}} // returns 'BBB'