<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Am I using modular regular expressions wrong? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439677#M76682</link>
    <description>&lt;P&gt;Yes, I'm sure. I'll update the answer with more specific code of what I'm doing. Thanks for hinting me at that app, however it strictly uses it with transforms field extractions which is exactly what the docs also do (unlike my example, which uses it for event routing).&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2019 07:48:05 GMT</pubDate>
    <dc:creator>jeffland</dc:creator>
    <dc:date>2019-05-07T07:48:05Z</dc:date>
    <item>
      <title>Am I using modular regular expressions wrong?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439673#M76678</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;

&lt;P&gt;I need to route my data to a different index and append something to the host field if a certain regex matches, following the well know method using props.conf and transforms.conf, for example documented &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/Indexer/Setupmultipleindexes#Route_specific_events_to_a_different_index"&gt;here&lt;/A&gt; but also mentioned in &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Admin/Transformsconf"&gt;transforms.conf&lt;/A&gt;. My transforms.conf looks like this (props.conf has &lt;CODE&gt;TRANSFORMS-class = route_host_by_foo,route_index_by_foo&lt;/CODE&gt; applying this to the appropriate data):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[route_host_by_foo]
REGEX = foo
DEST_KEY = MetaData:Host
FORMAT = $0_custom_suffix
# $0 already contains "host::", so no need to prepend

[route_index_by_foo]
REGEX = foo
DEST_KEY = _MetaData:Index
FORMAT = custom_index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is working fine. Since I need to change two DEST_KEYS, host and index, and this requires using two transforms.conf stanzas, I've tried to move my regex to a modular regular expression as documented &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/Admin/Transformsconf#transforms.conf.example"&gt;here&lt;/A&gt; (search for "MODULAR REGULAR EXPRESSION") to avoid redundant config. It looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[foo]
REGEX = foo

[route_host_by_foo]
REGEX = [[foo]]
DEST_KEY = MetaData:Host
FORMAT = $0_custom_suffix
# $0 already contains "host::", so no need to prepend

[route_index_by_foo]
REGEX = [[foo]]
DEST_KEY = _MetaData:Index
FORMAT = custom_index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Unfortunately, this doesn't work (same setup as before with props.conf), and I don't see why. Can someone explain?&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Update: To clarify, I'm obviously using a more complex regex than &lt;CODE&gt;foo&lt;/CODE&gt;. Here is my transforms:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# modular regexes
[app_1_schema]
REGEX = (?:regex_1|regex_2|...)

[app_1_user]
REGEX = (?:regex_3|regex_4|...)

[app_2_schema]
REGEX = (?:regex_5|regex_6|...)

[app_2_user]
REGEX = (?:regex_7|regex_8|...)

# actual props.conf mentioned transforms
[app_1_rewrite_index_by_user]
REGEX = &amp;lt;DB_User&amp;gt;([[app_1_schema]]|[[app_1_user]])&amp;lt;\/DB_User&amp;gt;
DEST_KEY = _MetaData:Index
FORMAT = app_2

[app_2_rewrite_index_by_user]
REGEX = &amp;lt;DB_User&amp;gt;([[app_2_schema]]|[[app_2_user]])&amp;lt;\/DB_User&amp;gt;
DEST_KEY = _MetaData:Index
FORMAT = app_1

[app_1_rewrite_host_by_user]
REGEX = &amp;lt;DB_User&amp;gt;([[app_1_schema]]|[[app_1_user]])&amp;lt;\/DB_User&amp;gt;
DEST_KEY = MetaData:Host
FORMAT = $0_app_2

[app_2_rewrite_host_by_user]
REGEX = &amp;lt;DB_User&amp;gt;([[app_2_schema]]|[[app_2_user]])&amp;lt;\/DB_User&amp;gt;
DEST_KEY = MetaData:Host
FORMAT = $0_app_1

[app_1_rewrite_index_by_schema]
REGEX = &amp;lt;Object_Schema&amp;gt;[[app_1_schema]]&amp;lt;\/Object_Schema&amp;gt;
DEST_KEY = _MetaData:Index
FORMAT = app_2

[app_2_rewrite_index_by_schema]
REGEX = &amp;lt;Object_Schema&amp;gt;[[app_2_schema]]&amp;lt;\/Object_Schema&amp;gt;
DEST_KEY = _MetaData:Index
FORMAT = app_1

[app_1_rewrite_host_by_schema]
REGEX = Object_Schema&amp;gt;[[app_1_schema]]&amp;lt;\/Object_Schema&amp;gt;
DEST_KEY = MetaData:Host
FORMAT = $0_app_2

[app_2_rewrite_host_by_schema]
REGEX = &amp;lt;Object_Schema&amp;gt;[[app_2_schema]]&amp;lt;\/Object_Schema&amp;gt;
DEST_KEY = MetaData:Host
FORMAT = $0_app_1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does not work. &lt;CODE&gt;'s/\[\[app_1_schema]]/(?:regex_1|regex_2|...)/g'&lt;/CODE&gt; etc. makes it work.&lt;BR /&gt;
Also, the events are not simply left untouched - they disappear. I have an index and host set up at the input level (on a forwarder), and there are events that do not match the above regexes. Those continue into their expected index regardless of whether I'm using modular regular expressions or not. The ones where the regex matches are either successfully routed to the new index with a new host as long as I'm using the explicit &lt;CODE&gt;REGEX&lt;/CODE&gt; in the transforms.conf stanza mentioned by props.conf, or they disappear when I use modular regular expressions.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 09:04:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439673#M76678</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2019-05-06T09:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using modular regular expressions wrong?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439674#M76679</link>
      <description>&lt;P&gt;Hi @jeffland,&lt;BR /&gt;
Try to use below &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DEST_KEY = MetaData:Host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since Keys are case-sensitive.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 09:20:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439674#M76679</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2019-05-06T09:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using modular regular expressions wrong?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439675#M76680</link>
      <description>&lt;P&gt;That was a typo in my question (now corrected), the config works as expected when not using modular regular expressions.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 09:35:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439675#M76680</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2019-05-06T09:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using modular regular expressions wrong?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439676#M76681</link>
      <description>&lt;P&gt;That seems like it should work to me; are you &lt;EM&gt;sure&lt;/EM&gt; that it doesn't?  For an example of a working app, you can see how this one does it:&lt;BR /&gt;
&lt;A href="https://splunkbase.splunk.com/app/3121/"&gt;https://splunkbase.splunk.com/app/3121/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 17:37:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439676#M76681</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-05-06T17:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using modular regular expressions wrong?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439677#M76682</link>
      <description>&lt;P&gt;Yes, I'm sure. I'll update the answer with more specific code of what I'm doing. Thanks for hinting me at that app, however it strictly uses it with transforms field extractions which is exactly what the docs also do (unlike my example, which uses it for event routing).&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 07:48:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439677#M76682</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2019-05-07T07:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Am I using modular regular expressions wrong?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439678#M76683</link>
      <description>&lt;P&gt;I would open a support case.&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 19:09:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Am-I-using-modular-regular-expressions-wrong/m-p/439678#M76683</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-05-11T19:09:08Z</dc:date>
    </item>
  </channel>
</rss>

