{"id":2597,"date":"2018-03-02T17:35:48","date_gmt":"2018-03-02T17:35:48","guid":{"rendered":"http:\/\/www.robertprice.co.uk\/robblog\/?p=2597"},"modified":"2018-03-02T17:35:48","modified_gmt":"2018-03-02T17:35:48","slug":"mendix-regexreplaceall-example","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/","title":{"rendered":"Extracting text in Mendix using RegexReplaceAll"},"content":{"rendered":"<p>It&#8217;s a fairly common requirement to be able to extract text from a larger string.<\/p>\n<p>Using Mendix, the easiest way I&#8217;ve found to do this is using the RegexReplaceAll Java action from the <a href=\"https:\/\/appstore.home.mendix.com\/link\/app\/170\/Mendix\/Community-Commons-Function-Library\">Community Commons module<\/a>.<\/p>\n<p>We use a regular expression extract the text, then return this selected text in the action.<\/p>\n<p>For example, take the following string returned from the <a href=\"https:\/\/appstore.home.mendix.com\/link\/app\/2168\/Finaps\/Nexmo-SMS-module\">Nexmo SMS<\/a> module.<\/p>\n<pre>\r\n--------- part [ 1 ] ------------Status [ 9 ] ...SUBMISSION FAILED!Message-Id [ null ] ...Error-Text [ Quota Exceeded - rejected ] ...Message-Price [ 0.03330000 ] ...Remaining-Balance [ 0.03200000 ]\r\n<\/pre>\n<p>If we want to extract the Error-Text we can use the following regular expression.<\/p>\n<pre>\r\n^.*Error-Text \\[ (.*?) \\].*$\r\n<\/pre>\n<p>Here we&#8217;re saying look for the text between the square brackets after the string Error-Text. We use round brackets to say we want to remember this matched text. We can then use the regular expression match position to return the matched text &#8211; in this case $1.<\/p>\n<p>If we run this over our string we get the following<\/p>\n<pre>\r\nQuota Exceeded - rejected\r\n<\/pre>\n<p>To use this in a Mendix microflow, assume we have our status message in a String $StatusMessage that we pass into the Java action. This is our Haystack.<\/p>\n<p>Next, we use the regular expression as a String for our Needle regex.<\/p>\n<p>Finally, we say we want $1 as a String to be our Replacement.<\/p>\n<p>We return the String as $Details.<\/p>\n<p>This is what the microflow and action should look like.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png\" alt=\"\" width=\"814\" height=\"414\" class=\"aligncenter size-full wp-image-2598\" srcset=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png 814w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow-300x153.png 300w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow-768x391.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexjavaaction.png\" alt=\"\" width=\"1246\" height=\"598\" class=\"aligncenter size-full wp-image-2599\" srcset=\"https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexjavaaction.png 1246w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexjavaaction-300x144.png 300w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexjavaaction-768x369.png 768w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexjavaaction-1024x491.png 1024w, https:\/\/www.robertprice.co.uk\/robblog\/assets\/regexjavaaction-1200x576.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>View <a href=\"https:\/\/developer.mendixcloud.com\/link\/profile\/57914\">Robert Price&#8217;s Mendix Profile<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s a fairly common requirement to be able to extract text from a larger string. Using Mendix, the easiest way I&#8217;ve found to do this is using the RegexReplaceAll Java action from the Community Commons module. We use a regular expression extract the text, then return this selected text in the action. For example, take &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Extracting text in Mendix using RegexReplaceAll&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[98],"class_list":["post-2597","post","type-post","status-publish","format-standard","hentry","category-dev","tag-mendix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Extracting text in Mendix using RegexReplaceAll - Robert Price<\/title>\n<meta name=\"description\" content=\"How to extract text in Mendix using the Community Commons RegexReplaceAll Java action.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Extracting text in Mendix using RegexReplaceAll - Robert Price\" \/>\n<meta property=\"og:description\" content=\"How to extract text in Mendix using the Community Commons RegexReplaceAll Java action.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-02T17:35:48+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Extracting text in Mendix using RegexReplaceAll\",\"datePublished\":\"2018-03-02T17:35:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/\"},\"wordCount\":219,\"image\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/regexmicroflow.png\",\"keywords\":[\"Mendix\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/\",\"name\":\"Extracting text in Mendix using RegexReplaceAll - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/regexmicroflow.png\",\"datePublished\":\"2018-03-02T17:35:48+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"description\":\"How to extract text in Mendix using the Community Commons RegexReplaceAll Java action.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/regexmicroflow.png\",\"contentUrl\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/assets\\\/regexmicroflow.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/mendix-regexreplaceall-example\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Extracting text in Mendix using RegexReplaceAll\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Extracting text in Mendix using RegexReplaceAll - Robert Price","description":"How to extract text in Mendix using the Community Commons RegexReplaceAll Java action.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/","og_locale":"en_GB","og_type":"article","og_title":"Extracting text in Mendix using RegexReplaceAll - Robert Price","og_description":"How to extract text in Mendix using the Community Commons RegexReplaceAll Java action.","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/","og_site_name":"Robert Price","article_published_time":"2018-03-02T17:35:48+00:00","og_image":[{"url":"http:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png","type":"","width":"","height":""}],"author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Extracting text in Mendix using RegexReplaceAll","datePublished":"2018-03-02T17:35:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/"},"wordCount":219,"image":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#primaryimage"},"thumbnailUrl":"http:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png","keywords":["Mendix"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/","name":"Extracting text in Mendix using RegexReplaceAll - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#primaryimage"},"image":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#primaryimage"},"thumbnailUrl":"http:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png","datePublished":"2018-03-02T17:35:48+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"description":"How to extract text in Mendix using the Community Commons RegexReplaceAll Java action.","breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#primaryimage","url":"http:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png","contentUrl":"http:\/\/www.robertprice.co.uk\/robblog\/assets\/regexmicroflow.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/mendix-regexreplaceall-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Extracting text in Mendix using RegexReplaceAll"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=2597"}],"version-history":[{"count":3,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2597\/revisions"}],"predecessor-version":[{"id":2602,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2597\/revisions\/2602"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=2597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=2597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=2597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}