import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<id>[^\\|]*)\\|(?<action>[^\\|]*)\\|(?<date_create>[^\\|]*)\\|(?<actor_type>[^\\|]*)\\|(?<actor_user_id>[^\\|]*)\\|(?<actor_user_name>[^\\|]*)\\|(?<actor_user_email>[^\\|]*)\\|(?<entity_type>[^\\|]*)\\|(?<entity_user_id>[^\\|]*)\\|(?<entity_user_name>[^\\|]*)\\|(?<entity_user_email>[^\\|]*)\\|(?<entity_workspace_id>[^\\|]*)\\|(?<entity_workspace_name>[^\\|]*)\\|(?<entity_workspace_domain>[^\\|]*)\\|(?<entity_enterprise_id>[^\\|]*)\\|(?<entity_enterprise_name>[^\\|]*)\\|(?<entity_enterprise_domain>[^\\|]*)\\|(?<entity_channel_id>[^\\|]*)\\|(?<entity_channel_name>[^\\|]*)\\|(?<entity_channel_privacy>[^\\|]*)\\|(?<entity_channel_is_shared>[^\\|]*)\\|(?<entity_channel_is_org_shared>[^\\|]*)\\|(?<entity_app_id>[^\\|]*)\\|(?<entity_app_name>[^\\|]*)\\|(?<entity_app_is_distributed>[^\\|]*)\\|(?<entity_app_is_directory_approved>[^\\|]*)\\|(?<entity_app_scopes>[^\\|]*)\\|(?<entity_file_id>[^\\|]*)\\|(?<entity_file_name>[^\\|]*)\\|(?<entity_file_filetype>[^\\|]*)\\|(?<entity_file_title>[^\\|]*)\\|(?<context_type>[^\\|]*)\\|(?<context_location_id>[^\\|]*)\\|(?<context_location_name>[^\\|]*)\\|(?<context_location_type>[^\\|]*)\\|(?<context_location_domain>[^\\|]*)\\|(?<context_ua>[^\\|]*)\\|(?<context_ipaddress>[^\\|]*)\\|(?<details_name>[^\\|]*)\\|(?<details_type>[^\\|]*)\\|(?<details_previous_value>[^\\|]*)\\|(?<details_new_value>[^\\|]*)\\|(?<details_export_type>[^\\|]*)\\|(?<details_export_start_ts>[^\\|]*)\\|(?<details_export_end_ts>[^\\|]*)\\|(?<details_is_internal_integration>[^\\|]*)\\|(?<details_kicker_id>[^\\|]*)\\|(?<details_kicker_name>[^\\|]*)\\|(?<details_kicker_email>[^\\|]*)\\|(?<details_inviter_id>[^\\|]*)\\|(?<details_inviter_name>[^\\|]*)\\|?(?<details_inviter_name2>[^\\|]*)\\|?(?<details_inviter_email>[\\w+]*)\n";
final String string = "f6c75963-192e-4cb7-b25e-aef5ca3dd7de|file_shared|02/05/2019 19:07|user|WC31RPBJ4|Saumya Khanna|Saumya.Khanna@marsh.com|file||||||||||||||||||||FFZ3JH8CV|image.png|image/png|Pasted image at 2019-02-05, 2:07 PM||EB6CVT82J|Marsh & McLennan Companies, Inc.|enterprise|mmc|||||||||||||||||\n\n"
+ "903dd3e5-6c28-49fa-bc4a-7997daa7abb5|user_channel_join|01/17/2019 20:01|user|WALL8ECLC|Mary Yao|Mary.Yao@oliverwyman.com|channel||||||||||CFGD6P552|studioculture|public|false|false|||||||||||TCX7L0SP5|NY Studio|workspace|ny-studio|Mozilla/5.0 (Windows NT 10.0.14393; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) AtomShell/3.3.3 Chrome/61.0.3163.100 Electron/2.0.7 Safari/537.36 Slack_SSB/3.3.3|167.245.255.229||INVITED||||||||||WA50E2AAX|Dustin Hughes|dustin.hughes@oliverwyman.com\n\n\n"
+ "(?<id>[^\\|]*)\\|(?<action>[^\\|]*)\\|(?<date_create>[^\\|]*)\\|(?<actor_type>[^\\|]*)\\|(?<actor_user_id>[^\\|]*)\\|(?<actor_user_name>[^\\|]*)\\|(?<actor_user_email>[^\\|]*)\\|(?<entity_type>[^\\|]*)\\|(?<entity_user_id>[^\\|]*)\\|(?<entity_user_name>[^\\|]*)\\|(?<entity_user_email>[^\\|]*)\\|(?<entity_workspace_id>[^\\|]*)\\|(?<entity_workspace_name>[^\\|]*)\\|(?<entity_workspace_domain>[^\\|]*)\\|(?<entity_enterprise_id>[^\\|]*)\\|(?<entity_enterprise_name>[^\\|]*)\\|(?<entity_enterprise_domain>[^\\|]*)\\|(?<entity_channel_id>[^\\|]*)\\|(?<entity_channel_name>[^\\|]*)\\|(?<entity_channel_privacy>[^\\|]*)\\|(?<entity_channel_is_shared>[^\\|]*)\\|(?<entity_channel_is_org_shared>[^\\|]*)\\|(?<entity_app_id>[^\\|]*)\\|(?<entity_app_name>[^\\|]*)\\|(?<entity_app_is_distributed>[^\\|]*)\\|(?<entity_app_is_directory_approved>[^\\|]*)\\|(?<entity_app_scopes>[^\\|]*)\\|(?<entity_file_id>[^\\|]*)\\|(?<entity_file_name>[^\\|]*)\\|(?<entity_file_filetype>[^\\|]*)\\|(?<entity_file_title>[^\\|]*)\\|(?<context_type>[^\\|]*)\\|(?<context_location_id>[^\\|]*)\\|(?<context_location_name>[^\\|]*)\\|(?<context_location_type>[^\\|]*)\\|(?<context_location_domain>[^\\|]*)\\|(?<context_ua>[^\\|]*)\\|(?<context_ipaddress>[^\\|]*)\\|(?<details_name>[^\\|]*)\\|(?<details_type>[^\\|]*)\\|(?<details_previous_value>[^\\|]*)\\|(?<details_new_value>[^\\|]*)\\|(?<details_export_type>[^\\|]*)\\|(?<details_export_start_ts>[^\\|]*)\\|(?<details_export_end_ts>[^\\|]*)\\|(?<details_is_internal_integration>[^\\|]*)\\|(?<details_kicker_id>[^\\|]*)\\|(?<details_kicker_name>[^\\|]*)\\|(?<details_kicker_email>[^\\|]*)\\|(?<details_inviter_id>[^\\|]*)\\|(?<details_inviter_name>[^\\|]*)\\|(?<details_inviter_email>(\\w+))?\\|";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html