Skip to main content
added 1 character in body
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)([^\\s\\|]*)(?=[$\\s\|]=[$\\s\\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0);
}
system.debug(emp);

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)([^\\s\\|]*)(?=[$\\s\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0);
}
system.debug(emp);

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)([^\\s\\|]*)(?=[$\\s\\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0);
}
system.debug(emp);
added 3 characters in body
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)(.*[^\\s\\|]*)(?=[$\\|]=[$\\s\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0).trim();
}
system.debug(emp);

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)(.*)(?=[$\\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0).trim();
}
system.debug(emp);

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)([^\\s\\|]*)(?=[$\\s\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0);
}
system.debug(emp);
added 407 characters in body
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)(.*)(?=[$\\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0).trim();
}
system.debug(emp);

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

This will split it and remove whitespace:

String initialString = 'Malcolm Bell Landgraab | EMP-00012 | Consultant';
String[] results = initialString.trim().split('\\s*\\|\\s*');
system.debug(results);

Of course you will want to add in all the usual checks for null, errors, etc.

For a single string this will get you the EMP part as requested in your comments:

Note I am not the best at regex so best I can do at this point:

Pattern MyPattern = Pattern.compile('(?<=EMP)(.*)(?=[$\\|])');
Matcher MyMatcher = MyPattern.matcher(initialString);
Boolean result = MyMatcher.find();
String emp;
if(result){
    emp = 'EMP' + MyMatcher.group(0).trim();
}
system.debug(emp);
added 11 characters in body
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196
Loading
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196
Loading