0

enter image description here

I do not know why there's asterisks in between the terms. How do I write a regular expression to get that returns only the letters and numbers without the asterisks in between ?

The regular expression I tried is: CUST_NUM_REMITT_AMT_REGEX => qr/^\w+ \w+ (.?) (.?)$/ It is in a perl statement that is:

($edi_h{$process_data}{$get_remitt_data}{cust_num},
$edi_h{$process_data}{$get_remitt_data}{remitt_amt}) =
$rec =~ /$regex_h{CUST_NUM_REMITT_AMT_REGEX}/
if ($rec =~ /$regex_h{REMITT_IND}/);
($edi_h{$process_data}{$get_remitt_data}{cust_num}) = " ";

This expression is returning blank customer number, but the amount has an asterisk in front of it.

Is the question mark returning the result?

There is this line earlier in the code

$/ = $sav_delimiter;
(@recs) = $file_data =~ /(.*?)\n/g;
Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37
Anna
  • 57
  • 5
  • I see you updated the question to include sample text "\RMR*IV*43070661**5759.61". Can you also provide what you expect the text to be? You said to remove the asterisks, but do you want to run everything together like "/RMRIV430706615759.61" or should the asterisks be replaced with spaces or something? – Andy Feb 03 '21 at 18:25
  • Also, I'm unfamiliar with the `=~` syntax. What language is this running in? Sometimes there are regex differences depending on the runtime. – Andy Feb 03 '21 at 18:26
  • 1
    the =~ syntax tells Perl to apply a regular expression. – Anna Feb 03 '21 at 18:38
  • I believe there should be a space each term – Anna Feb 03 '21 at 18:43

1 Answers1

0

const input = "RMR*IV*43070661**5759.61";
const regex = /\*+/g;
console.log(input.replace(regex, " "));

This regular expression matches one or more adjacent asterisks. Because * has special meaning in a regular expression, it has to be escaped with the backslash. I'm also using the global option (the g at the end) to make it apply to all occurrences instead of just the first one.

I then use the string.replace function in JavaScript to replace those asterisks with a single space. I'm not familiar with perl, but I assume there is a similar construct for replacing matches found with a regular expression with another string.

Andy
  • 648
  • 8
  • 21