Skip to content

Commit 8b92b1f

Browse files
committed
feat: add wildcard support to regex search
1 parent a7480fa commit 8b92b1f

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

includes/admin/feedzy-rss-feeds-actions.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,22 @@ private function search_replace() {
400400
$content = call_user_func( array( $this, $this->current_job->tag ) );
401401
$search = $this->current_job->data->search;
402402
$replace = $this->current_job->data->searchWith;
403+
$mode = isset( $this->current_job->data->mode ) ? $this->current_job->data->mode : 'text';
404+
405+
switch ( $mode ) {
406+
case 'wildcard':
407+
$pattern = preg_quote( $search, '/' );
408+
$pattern = str_replace( '\\*', '.*', $pattern );
409+
return preg_replace( '/' . $pattern . '/i', $replace, $content );
410+
case 'regex':
411+
if ( ! preg_match( '/^\/.\/[imsxuADU]$/', $search ) ) {
412+
$pattern = '/' . $search . '/i';
413+
}
403414

404-
if ( ! preg_match( '/^\/.*\/[imsxuADU]*$/', $search ) ) {
405-
$search = '/' . $search . '/i';
415+
return preg_replace( $pattern, $replace, $content );
416+
default:
417+
return str_replace( $search, $replace, $content );
406418
}
407-
408-
return preg_replace( $search, $replace, $content );
409419
}
410420

411421
/**

js/ActionPopup/SortableItem.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
113113
<div className="fz-action-event">
114114
<PanelBody title={ __( 'Search and Replace', 'feedzy-rss-feeds' ) } icon={ DragHandle } initialOpen={ false }>
115115
<PanelRow>
116+
<BaseControl>
117+
<SelectControl
118+
label={ __( 'Type', 'feedzy-rss-feeds' ) }
119+
value={ item.data.mode || 'text' }
120+
options={[
121+
{
122+
label: __( 'Text', 'feedzy-rss-feeds' ),
123+
value: 'text',
124+
},
125+
{
126+
label: __( 'Regex', 'feedzy-rss-feeds' ),
127+
value: 'regex',
128+
},
129+
{
130+
label: __( 'Wildcard', 'feedzy-rss-feeds' ),
131+
value: 'wildcard',
132+
}
133+
]}
134+
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'mode': currentValue ?? 'text' } ) }
135+
/>
136+
</BaseControl>
116137
<BaseControl>
117138
<TextControl
118139
type="text"

0 commit comments

Comments
 (0)