Skip to content

Conversation

@LaurenceJJones
Copy link
Member

@LaurenceJJones LaurenceJJones commented Aug 4, 2025

🎯 Summary

Added regex replacement functions and ANSI escape sequence handling to the expression helpers library.

to help with crowdsecurity/hub#1430

The idea would be to use it as a transform in this case:

source: docker
container_name:
 - my-uptime 
labels:
  type: uptime-kuma
transform: "ReplaceAllRegex(AnsiRegex(), evt.Line.Raw, '')"

Functions**

  • ReplaceRegexp() - Replaces only the first occurrence of a regex pattern
  • ReplaceAllRegex() - Replaces all occurrences of a regex pattern
  • AnsiRegex() - Returns regex pattern for ANSI escape sequences

ANSI Escape Sequence Support

  • Handles both hexadecimal (\x1b) and octal (\033) representations
  • Matches all standard ANSI color codes, formatting codes, and extended colors
  • Compatible with the existing regex replacement functions

Basic Regex Replacement

// Replace first occurrence
ReplaceRegexp("foo", "foobar foobaz", "qux") // → "quxbar foobaz"

// Replace all occurrences  
ReplaceAllRegex("foo", "foobar foobaz", "qux") // → "quxbar quxbaz"

ANSI Code Stripping

// Strip all ANSI codes
ReplaceAllRegex(AnsiRegex(), "\x1b[31mHello\x1b[0m \033[32mWorld\033[0m", "") 
// → "Hello World"

// Strip only first ANSI code
ReplaceRegexp(AnsiRegex(), "\x1b[31mHello\x1b[0m \033[32mWorld\033[0m", "")
// → "Hello\x1b[0m \033[32mWorld\033[0m"

@github-actions
Copy link

github-actions bot commented Aug 4, 2025

@LaurenceJJones: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind fix
  • /kind chore
  • /kind dependencies
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@github-actions
Copy link

github-actions bot commented Aug 4, 2025

@LaurenceJJones: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@codecov
Copy link

codecov bot commented Aug 4, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.66%. Comparing base (1f9bee8) to head (5950656).
⚠️ Report is 141 commits behind head on master.

Files with missing lines Patch % Lines
pkg/exprhelpers/strings.go 93.33% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3782      +/-   ##
==========================================
+ Coverage   60.63%   60.66%   +0.03%     
==========================================
  Files         410      410              
  Lines       42614    42659      +45     
==========================================
+ Hits        25838    25880      +42     
- Misses      14640    14642       +2     
- Partials     2136     2137       +1     
Flag Coverage Δ
bats 44.64% <0.00%> (-0.07%) ⬇️
unit-linux 33.97% <93.33%> (+0.05%) ⬆️
unit-windows 24.26% <93.33%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mmetc mmetc added this to the Next release milestone Aug 26, 2025
@mmetc mmetc modified the milestones: Next release, 1.7.6, 1.7.7 Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent kind/enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants