1

I have a str like this;

"B S <b.s@msoft.com>; J T <j.t@msoft.com>; A M <a.m@msoft.com>"

and i want to return to this format;

"b.s@msoft.com, j.t@msoft.com, a.m@msoft.com"

how i can do this?


str mail, a, mnew;
int b, c;
List strlist = new List(Types::String);
ListIterator iterator;
mail = "B S <b.s@msoft.com>; J T <j.t@msoft.com>; A M <a.m@msoft.com>";

strlist = strSplit(mail,';');

iterator = new ListIterator(strlist);

while (iterator.more())
{
    if (strcontains(iterator.value(), "<"))
    {
        b = strFind(iterator.value(), "<", 1, strLen(iterator.value()));
        c = strFind(iterator.value(), ">", 1, strLen(iterator.value()));
        info(strFmt("%1",subStr(strRem(iterator.value(),'>'),b+1,c)));
    }
    else
    {
        info(strFmt("%1",strLRTrim(iterator.value())));
    }
    iterator.next();
}

I do this with string runtime funtions. How can do it with regexp?

Aliaksandr Maksimau
  • 2,251
  • 12
  • 21
Mumble
  • 141
  • 1
  • 8
  • I hope those are fake emails. Are you missing a `>` after `brandon[...]@[...].com`? If yes, then it looks like you can look for pairs of `<` and `>` symbols and take the text between them to build your result. Do you want to implement this in [tag:x++]? Are you familiar with regular expressions? What version of Dynamics AX are you using? – FH-Inway Apr 17 '20 at 08:53
  • Hi FH-Inway, thanks for your answer. Yes these are fake emails and yes i missed > after first e-mail, sorry. I am using Dynamics AX 2012 R3, and i will use it in a job in MorphX. How can i do this "look for pairs of < and > symbols and take the text between them to build your result." ? I tried string runtime functions but i didn't, please help me – Mumble Apr 17 '20 at 09:54
  • Could you [edit] into your question what issues you had with the string runtime functions? If you add some code of the job you have tried so far, you will have better chances of getting an answer. – FH-Inway Apr 17 '20 at 10:05
  • Can you help me for solution with regexp ? @FH-Inway – Mumble Apr 17 '20 at 11:42
  • 1
    Well, [you know what they say about regular expressions](https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/) ;) But take a look at https://regex101.com/r/QAqBXC/2 and http://fourone.se/blog/2009/10/02/using-regular-expressions-in-dynamics-ax/ to get started. – FH-Inway Apr 17 '20 at 12:28

1 Answers1

3

Please check below one of the possible examples with regular expressions:

TextBuffer  textBuffer = new TextBuffer();
int         pos, len;
str         res;
;

textBuffer.setText("Brandon Smith <brandon.smith@msoft.com>; Jake Tyler <jake.tyler@msoft.com>; Amelia Miler <amelia.miler@msoft.com>");
textBuffer.regularExpressions(true);

while (textBuffer.find(@'\<[a-z0-9.@]+\>', pos))
{
    pos = textBuffer.matchPos();
    len = textBuffer.matchLen();

    res = (res == '') ? textBuffer.subStr(pos, len) : res + ', ' + textBuffer.subStr(pos, len);

    pos++;
}

textBuffer.setText(res);
textBuffer.removeChar('<>');

info(textBuffer.getText());

infolog

FH-Inway
  • 4,432
  • 1
  • 20
  • 37
Aliaksandr Maksimau
  • 2,251
  • 12
  • 21